Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Git course
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
courses
Git course
Commits
cf57f3bd
Commit
cf57f3bd
authored
10 years ago
by
bow
Browse files
Options
Downloads
Patches
Plain Diff
Ready version of tips presentation
parent
149fb8f2
No related branches found
No related tags found
1 merge request
!3
Updates bow
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tips/tips.tex
+300
-6
300 additions, 6 deletions
tips/tips.tex
with
300 additions
and
6 deletions
tips/tips.tex
+
300
−
6
View file @
cf57f3bd
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
\title
{
Git Tips and Tricks
}
\title
{
Git Tips and Tricks
}
\providecommand
{
\myConference
}{
Git course
}
\providecommand
{
\myConference
}{
Git course
}
\providecommand
{
\myDate
}{
Monday, Ju
ly 7
, 2014
}
\providecommand
{
\myDate
}{
Monday, Ju
ne 23
, 2014
}
\author
{
Wibowo Arindrarto
}
\author
{
Wibowo Arindrarto
}
\providecommand
{
\myGroup
}{
Sequencing Analysis Support Core
}
\providecommand
{
\myGroup
}{
Sequencing Analysis Support Core
}
\providecommand
{
\myDepartment
}{}
\providecommand
{
\myDepartment
}{}
...
@@ -43,6 +43,269 @@
...
@@ -43,6 +43,269 @@
\end{frame}
\end{frame}
\section
{
Custom Prompt
}
\begin{frame}
[fragile]
\frametitle
{}
Checking which branch you are working on and its status is
a routine task.
\bigskip
\pause
``
\bt
{
git status
}
'' is useful, but quickly feels repetitive.
\begin{lstlisting}
[language=none, caption=Routine git checking]
$
git branch
*
master
$
git status
nothing to commit, working directory clean
\end{lstlisting}
\bigskip
\pause
Solution: use a custom shell prompt that displays git status.
\begin{lstlisting}
[language=none, caption=Git checking with custom prompt]
(master)
$
git st
nothing to commit, working directory clean
\end
{
lstlisting
}
\bigskip
\end
{
frame
}
\section
{
Custom Prompt
}
\begin
{
frame
}
[
fragile
]
\frametitle
{}
The git
-
approved way to do this is to use the ``
\bt
{
\_\_
git
\_
ps
1
}
''
shell function defined in the ``
\bt
{
git
-
prompt.sh
}
'' file.
\bigskip
\pause
The location of this file depends on your OS and git version. For now,
you can download a copy of this file from our GitLab.
\bigskip
\pause
Then, in you ``
\bt
{
.bashrc
}
'' file, add ``
\bt
{
\_\_
git
\_
ps
1
}
'' to the
``
\bt
{
PS
1
}
'' variable, and source your ``
\bt
{
.bashrc
}
'' again.
\bigskip
\end
{
frame
}
\section
{
Useful git commands
}
\begin
{
frame
}
[
fragile
]
\frametitle
{
git blame
}
Git tracks each line of each file in its repository.
\bigskip
\pause
You can view who committed the line change, the commit hash,
and the commit time using ``
\bt
{
git blame
}
''
\begin
{
lstlisting
}
[
language
=
none, caption
=
git blame command
]
$
git blame README
a4394d28 (bow 2014-06 ...) Second version.
\end{lstlisting}
\bigskip
\end{frame}
\section
{
Useful git commands
}
\begin{frame}
[fragile]
\frametitle
{
git tag
}
Sometimes, it is practical to refer to a commit with a name
instead of a hash.
\bigskip
\pause
Official releases, for example, are better referred as v1.0
than a76a0fx.
\bigskip
\pause
This can be done using ``
\bt
{
git tag
}
''.
\end{frame}
\section
{
Useful git commands
}
\begin{frame}
[fragile]
\frametitle
{
git tag
}
\begin{lstlisting}
[language=none, caption=Adding a tag]
$
git tag "v
0
.
0
.
1
"
$
git show v0.0.1
commit a4394d28e6ba30be19318ee74f732a103b8ffdf2
Author: bow <bow@bow.web.id>
Date: Sat Jun 21 13:47:03 2014 +0200
Second commit
diff --git a/README b/README
index efe6f7c..4fe6328 100644
--- a/README
+++ b/README
@@ -1 +1 @@
-First version.
+Second version.
\end{lstlisting}
\bigskip
\end{frame}
\section
{
Useful git commands
}
\begin{frame}
[fragile]
\frametitle
{
git tag
}
What we did previously is to add what is called a lightweight tag.
Lightweight tags are essentially commit aliases.
\bigskip
\pause
There is another type of tag, called the annotated tag.
\bigskip
\pause
Annotated tags contain more information: tagger identity,
tagging message, tagging date, and can be verified with GPG.
\bigskip
\end{frame}
\section
{
Useful git commands
}
\begin{frame}
[fragile]
\frametitle
{
git tag
}
\begin{lstlisting}
[language=none, caption=Adding an annotated tag]
$
git tag
-
a "v
0
.
0
.
1
"
-
m "Alpha version"
tag v
0
.
1
.
0
Tagger: bow <bow@bow.web.id>
Date: Sat Jun
21
15
:
11
:
53
2014
+
0200
Alpha version
commit a
4394
d
28
e
6
ba
30
be
19318
ee
74
f
732
a
103
b
8
ffdf
2
Author: bow <bow@bow.web.id>
Date: Sat Jun
21
13
:
47
:
03
2014
+
0200
Second commit
diff
--
git a
/
README b
/
README
index efe
6
f
7
c..
4
fe
6328
100644
---
a
/
README
+++
b
/
README
@@
-
1
+
1
@@
-
First version.
+
Second version.
\end
{
lstlisting
}
\bigskip
\end
{
frame
}
\section
{
Useful git options
}
\begin
{
frame
}
[
fragile
]
\frametitle
{
git diff
-
w
}
Sometimes, you want to hide whitespace differences when using
``
\bt
{
git diff
}
''.
\bigskip
\pause
This can be done via ``
\bt
{
git diff
-
w
}
''
\begin
{
lstlisting
}
[
language
=
none, caption
=
git diff without whitespace
]
$
git diff -w
\end{lstlisting}
\bigskip
\pause
Note that while this aids visualization of the diff, git will still
commit the whitespace change.
\bigskip
\end{frame}
\section
{
Useful git options
}
\begin{frame}
[fragile]
\frametitle
{
git commit --amend
}
Git gives you total control over your history, which means you can also
change them.
\bigskip
\pause
This practice is potentially dangerous and should not be part of your
regular workflow. This is especially true for public commits.
\bigskip
\pause
Still, there are times when changing that one last commit makes more
sense than doing a ``
\bt
{
git revert
}
''
\bigskip
\pause
``
\bt
{
git commit --amend
}
'' allows you to do that: changing your last
commit.
\bigskip
\end{frame}
\section
{
Useful git options
}
\begin{frame}
[fragile]
\frametitle
{
git commit --amend
}
When run on a clean branch (no uncommitted changes),
``
\bt
{
git commit --amend
}
'' allows you to change your last commit message.
\bigskip
\pause
You can also use the command to meld current staged changes to your last
committed change.
\begin{lstlisting}
[language=none, caption=git blame command]
$
git status
Changes to be committed:
modified: README
$
git commit --amend -m "Update README"
[master b60437d] Second update
1 file changed, 1 insertion(+), 1 deletion(-)
\end{lstlisting}
\bigskip
\end{frame}
\section
{
Useful git options
}
\begin{frame}
[fragile]
\frametitle
{
git add --patch
}
Often, uncommited change overextends. You start with the intention of
fixing bug A, but in the middle found that you can implement feature B
and feature C while also squashing bug D.
\bigskip
\pause
At the end of the day, only ``
\bt
{
git commit -am "Updates"
}
'' is done
and the whole change is saved in a single comit.
\bigskip
\pause
This defeats the purpose of tracking your changes in commits. Commits
ideally represents a single, functional update, which you can understand
later on.
\bigskip
\end{frame}
\section
{
Useful git options
}
\begin{frame}
[fragile]
\frametitle
{
git add --patch
}
You can, infact, commit the line changes selectively. This helps
split a mesh of changes into separate commits.
\begin{lstlisting}
[language=none, caption=git add --patch]
$
git add
--
patch
\end
{
lstlisting
}
\bigskip
\end
{
frame
}
\section
{
Main Configuration File
}
\section
{
Main Configuration File
}
\begin
{
frame
}
[
fragile
]
\begin
{
frame
}
[
fragile
]
\frametitle
{
Viewing
}
\frametitle
{
Viewing
}
...
@@ -75,13 +338,14 @@
...
@@ -75,13 +338,14 @@
\bigskip
\bigskip
\pause
\pause
You can also use the ``
\bt
{
git config
}
'' to set the values via the shell.
You can also use the ``
\bt
{
git config
--
global
}
'' to set the values via the shell.
\begin
{
lstlisting
}
[
language
=
none, caption
=
Modifying via the shell
]
\begin
{
lstlisting
}
[
language
=
none, caption
=
Modifying via the shell
]
$
git config user.name "Linus Torvalds"
$
git config
--global
user.name "Linus Torvalds"
\end{lstlisting}
\end{lstlisting}
\bigskip
\bigskip
\end{frame}
\end{frame}
\section
{
Main Configuration File
}
\section
{
Main Configuration File
}
\begin{frame}
[fragile]
\begin{frame}
[fragile]
\frametitle
{
Modifying: global ignore
}
\frametitle
{
Modifying: global ignore
}
...
@@ -114,7 +378,8 @@
...
@@ -114,7 +378,8 @@
\begin{lstlisting}
[language=none, caption=Setting the global ignore file]
\begin{lstlisting}
[language=none, caption=Setting the global ignore file]
$
echo "
*
.out" > ~
/
.gitignore
_
global
$
echo "
*
.out" > ~
/
.gitignore
_
global
$
echo "testing.txt" > ~/.gitignore
_
global
$
echo "testing.txt" > ~/.gitignore
_
global
$
git config core.excludesfile "~/.gitignore
_
global"
$
git config
--
global core.excludesfile
\
"~
/
.gitignore
_
global"
\end
{
lstlisting
}
\end
{
lstlisting
}
\bigskip
\bigskip
\pause
\pause
...
@@ -129,6 +394,37 @@
...
@@ -129,6 +394,37 @@
\end{frame}
\end{frame}
\section
{
Main Configuration File
}
\begin{frame}
[fragile]
\frametitle
{
Aliases
}
You can alias simple commands.
\begin{lstlisting}
[language=none, caption=Simple alias]
$
git config
--
global alias.st status
$
git st
nothing to commit, working directory clean
\end{lstlisting}
\bigskip
\pause
Or more complex commands.
\begin{lstlisting}
[language=none, caption=Complex alias]
$
git config
--
global alias.qlog
\
"log
--
pretty
=
oneline"
$
git qlog
a4394d28e... Second commit
80eafd7e6... First commit
\end{lstlisting}
\bigskip
\end{frame}
\section
{
GitLab and GitHub
}
\begin{frame}
[fragile]
\frametitle
{
Demo time!
}
\end{frame}
\section
{
Questions?
}
\section
{
Questions?
}
\lastpagetemplate
\lastpagetemplate
\begin{fframe}
\begin{fframe}
...
@@ -141,8 +437,6 @@
...
@@ -141,8 +437,6 @@
Jeroen F. J. Laros
Jeroen F. J. Laros
Zuotian Tatum
\end{center}
\end{center}
\vfill
\vfill
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment