Git Flashcards

1
Q
stage file(s) in git
start tracking file(s) in git
A

git add «file1» («file2» «file3»)
git add «folder»

» adds precisely this content to the next commit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

show git commit history of the branch

A

git log

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is a git remote?

A

a label to a url

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

add git remote with a label?

A

git remote add «remote name» «remote label»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

show git remotes and their remote URLs

A

git remote -v

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

stage all file modifications and new files in git

A

git add .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

show local git branches

A

git branch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

show remote git branches

A

git branch -r

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

show all git branches

A

git branch -a

git branch –all

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

create and switch to new git branch

A

git switch -c «branch»

git checkout -b «branch»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

download git repository

A

git clone «repository url»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

update local cache of specific git remote and remove outdated branch trackings

A

git fetch «remote» –prune

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

download git repo to specific folder

A

git clone «repository url» «folder»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

show short version of git status

what is left and what is right?

A

git status -s

» left: status of staging area
» right: status of workspace

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

show differences between git staging area and workspace

A

git diff

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

show differences between git staging area and last commit

A

git diff –cached

git diff –staged

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

commit all already tracked files in git

A

git commit -a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

delete file(s) and remove file(s) from git as well

A

git rm «file1» («file2 «file3»)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

delete file(s) and remove file(s) from git when content was modified or staged

A

git rm -f «file1» («file2 «file3»)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

remove file(s) from git only

A

git rm –cached «file1» («file2 «file3»)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

show preformatted git log

A

git log –pretty=oneline/short/full/fuller

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

show git logs with ASCI graph

A

git log –graph

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

show all git commits that changed a specific string

A

git log -S «string»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

show all git commits with specific string in commit message

A

git log –grep=«string»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

show all git commits without merge commits

A

git log –no-merges

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

change git commit message

add or update files of last commit

A

git commit –amend

» overwrites commit with current staging area

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

unstage file in git

A

git reset «file»
git restore –staged «file»
*git unstage «file»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

reset file in workspace to status of last git commit

A

git checkout – «file»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

what is the difference between git fetch and git pull?

A

pull = fetch + merge

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

change name of git remote

A

git remote rename «old name» «new name»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

what additional information does an annotated git tag contain apart from tag name?

A

» tagger email
» tag date
» tag message

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

create lightweight git tag

A

git tag «tag name»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

create annotated git tag with a message

A

git tag -a «tag name» -m «commit message»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

put leightweight tag on existing git commit

A

git tag «commit» «tag name»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

upload specific git tag on the remote

A

git push «remote» «tag name»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

delete local git tag

A

git tag -d «tag name»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

delete branch on git remote

A

git push «remote» –delete «remote branch»
git push «remote» -d «remote branch»
git push «remote» :«remote branch»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

create alias for git command

A

git config –global alias.«alias name» ‘«git command»’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

show all git commits of specific branch

A

git log «local branch»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

show all git commits of all branches

A

git log –all

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

delete local git branch

A

git branch -d «local branch»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

how does ‘git merge «branch»’ work?

A

» tries to merge «branch» into current branch

If the merge fails:
» resolve merge conflicts
» stage resolved files
» complete with ‘git commit’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

show all merged in git branches

A

git branch –merged

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

show all not yet merged in git branches

A

git branch –no-merged

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

update local cache of specific git remote

A

git fetch «remote»

» new remote branches don’t create local copies

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

push git branch to specific remote branch

A

git push «remote» «local branch»:«remote branch»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

create, name and switch to branch and track specific remote git branch

A

git switch -c «local branch» «remote»/«remote branch»

git checkout -b «local branch» –track «remote»/«remote branch»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

create, name and switch to branch and do not track any remote branch

A

git switch -c «branch» –no-track

git checkout -b «branch» –no-track

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

set or update the current git branch’s tracking to specific remote branch

A

git branch -u «remote»/«remote branch»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

get git remote tracking status of all branches

A

git fetch –all; git branch -vv

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

rebase git branch onto another branch

A

git rebase «base branch» «head branch»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

add file removal(s) to git staging area

A

git add «file1» («file2 «file3»)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

push a rebased git branch to remote

A

git push «remote» «local branch» –force-with-lease

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

merge in whole git branch as a commit

A

git merge –squash «local branch»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

do one time git pull by url

A

git pull «remote url»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

show git commits of one branch since last common ancestor with another branch

A

git log «old branch»..«new branch»
git log ^«old branch» «new branch»
git log «new branch» –not «old branch»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
57
Q

show git commits of both branches since last common ancestor with another branch

A

git log «branch1»…«branch2»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
Q

show git commits with short hashes

A

git log –abbrev-commit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
59
Q

show a git commit’s details

A

git show «commit»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
60
Q

show a git commit parent’s details

A

git show «commit»^

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
61
Q

enter interactive git staging

A

git add -i

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
62
Q

partially add git file

A

git add -p «file»

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
63
Q

save current work on tracked files without git commit and reset workspace

A

git stash

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

restore last saved uncommitted work in git

A

git stash apply

65
Q

restore older than last saved uncommitted work in git

A

git stash apply «stash number»

66
Q

show all saved uncommitted work in git

A

git stash list

67
Q

restore last saved uncommitted work and git staging

A

git stash apply –index

68
Q

save current work on tracked files without git commit but keep the git staging and reset workspace

A

git stash -k

69
Q

save current work without git commit including untracked files and reset workspace

A

git stash -u

70
Q

save current work without git commit including untracked and explicitly ignored files and reset workspace

A

git stash -a

71
Q

partially save parts of current work without git commit and reset workspace

A

git stash -p

72
Q

create git branch from last saved uncommitted work

A

git stash branch «branch name»

73
Q

show git history of a specific function in s specific file

A

git log -L :«function name»:«specific file»

74
Q

add or update files of last git commit without changing commit message

A

git commit –amend –no-edit

» overwrites commit with current staging area

75
Q

interactively rewrite git history of last «X» commits

A

git rebase -i HEAD~«X»

76
Q

reset branch to a specific git commit and clear staging area

A

git reset «commit»

» keeps workspace

77
Q

reset branch to a specific git commit and put newer commit contents in staging area

A

git reset –soft «commit»

» keeps workspace

78
Q

reset branch and workspace to a specific git commit and clear staging area

A

git reset –hard «commit»

» risk of loosing data (!)

79
Q

add or reset file in staging area from another git commit

A

git reset «commit» – «file»

80
Q

what does the git – option mean?

A

do not interpret any more command arguments as options

81
Q

cancel a merge in git

A

git merge –abort

82
Q

merge and ignore git whitespace issues

A

git merge -Xignore-all-space

git merge -Xignore-space-change

» treats one ore more whitespace characters as equivalent

83
Q

merge in a file from another git commit or branch

A

git checkout «commit/branch» «file»

84
Q

reset a file’s git merge conflict markers

A

git checkout –conflict «file»

85
Q

reset and show details of a file’s git merge conflicts

A

git checkout –conflict=diff3 «file»

86
Q

solve git merge conflict by choosing the file’s workspace version

A

git checkout –ours «file»

87
Q

solve git merge conflict by choosing the file’s merge branch version

A

git checkout –theirs «file»

88
Q

show log of full git merge

A

git log –oneline –left-right HEAD…MERGE_HEAD

89
Q

show log of git merge conflict commits

A

git log –oneline –left-right –merge

90
Q

show log of git merge conflict differences

A

git log –oneline –left-right -p

91
Q

undo a git commit by doing another cancelling commit

A

git revert «commit to undo»

92
Q

fake the git merge of another branch into current branch

A

git merge -s ours «incoming branch»

93
Q

show git history of a file’s line range

A

git blame -L «from line»,«to line» «file»

94
Q

show git history of a file including line movements from other files

A

git blame -C «file»

95
Q

how tu use git binary search to find erroneous commit

A

git bisect start
git bisect bad (marks current state as bad)
git bisect good «commit» (was last good commit)
» git bisect good/bad
git bisect reset

96
Q

add git submodule from URL

A

git add submodule «submodule url»

97
Q

download a git repository including all submodules (and all their submodules)

A
git clone «repository url»
git submodule init
git submodule update
-------------------
git clone «repository url»
git submodule update --init (--recursive)
-------------------
git clone «repository url» --recurse-submodules
98
Q

update all git submodules from it’s remote tracking

A

git submodule update –remote

» puts submodule into detached HEAD state

99
Q

update a specific git submodule it’s remote tracking

A

git submodule update –remote «submodule»

100
Q

set a git submodule’s tracking branch

A

git config -f .gitmodules submodule.«submodule name».branch «remote tracking branch»

101
Q

update git submodule (and their submodule) after pull from superproject

A
(git pull)
git submodule update --init (--recursive)
102
Q

update git submodule from it’s remote keeping our changes

A
cd «submodule folder»
git checkout «new branch»
cd .. (back into superproject folder)

git submodule update –remote –merge/rebase

  • git supdate
103
Q

upload local changes of git submodule

A

cd «submodule folder»
git push
——————-
git push –recurse-submodules=on-demand

» tries to push submodule before pushing superproject

  • git spush
104
Q

create new git branch of project with submodule(s)

A

git submodule foreach ‘git switch -c «branch»’

105
Q

show differences between git staging area and workspace including submodules

A

git diff
git submodule foreach ‘git diff’
——————-
*git sdiff

106
Q

set git config variable

A

git config (–global) «setting» «value»

107
Q

create git bundle file of a commit range and name it

A

git bundle create «file name».bundle «head commit» ^«base commit»
git bundle create «file name».bundle «base commit»..«head commit»

108
Q

create git bundle file of the whole branch and name it

A

git bundle create «file name».bundle HEAD «branch»

109
Q

check if git bundle is valid

A

git bundle verify «file name»

110
Q

create new git branch

A

git branch «branch name»

111
Q

create new git branch based on a commit

A

git branch «branch name» «commit»

112
Q

show all git tags

A

git tag

113
Q

show all configured git aliases

A

git config –list | grep alias

114
Q

show last git commit

A

git log -1 HEAD

*git last

115
Q

upload a local branch to the git remote

A

git push «remote» «local branch»

116
Q

upload all local branches to the git remote

A

git push –all «remote»

117
Q

upload a local branch to a specific branch of the git remote

A

git push «remote» «local branch»:«remote branch»

118
Q

upload a local branch to the git remote and save as remote tracking default

A

git push -u «remote» «local branch»

» «remote» and «local branch» can be omitted from now on

119
Q

stage all file modifications and deletions in git

A

git add -u

120
Q

stage all file modifications, new files and deletions in git

A

git add -A

121
Q

update local branch cache of this branch’s git remote

A

git fetch

» new remote branches don’t create local copies

122
Q

show not yet merged in branches into specific git branch

A

git branch –merged

123
Q

show merged in branches into specific git branch

A

git branch –no-merged

124
Q

rebase current branch on top of another base git branch?

A

git rebase «base branch»

125
Q

update local cache of all git remotes and remove outdated branch trackings

A

git fetch –prune

126
Q

remove folder from git and delete folder from workspace

A

git rm -r «folder»

127
Q

remove folder from git and delete folder from workspace

A

git rm -r «folder»

128
Q

update all new git tags on the remote

A

git push «remote» –tags

129
Q

delete tag on git remote

A

git push «remote» –delete «tag name»
git push «remote» -D «tag name»
git push «remote» :«tag name»

130
Q

update local cache of all git remotes

A

git fetch –all

» new remote branches don’t create local copies

131
Q

update local cache of a specific git remote’s branch

A

git fetch «remote» «remote branch»

132
Q

switch back to previous git branch

A

git switch -

133
Q

create, switch to and do not track local copy of a specific git remote’s branch

A

git switch -c –no-track «remote»/«remote branch»

git checkout -b «remote»/«remote branch»

134
Q

create, switch to and track local copy of a specific git remote’s branch

A

git switch –track «remote»/«remote branch»

git checkout –track «remote»/«remote branch»

135
Q

create branch based on a git commit

A

git switch -c «branch» «commit»

136
Q

switch to git commit and detach from HEAD for temporary inspection

A

git switch –detach «commit»

git checkout «commit»

137
Q

create and track local copy of remote git branch and switch to it

A

git switch «remote branch»

git checkout «remote branch»

138
Q

set or update another local branch’s git tracking to a specific remote branch

A

git branch -u «remote»/«remote branch» «local branch»

139
Q

unite last «X» git commits to one

A

git reset –soft HEAD~«X»; git commit

140
Q

show all git commit’s details since last common ancestor of two branches

A

git diff –left-right «branch1»…«branch2»

141
Q

show git commit’s details of a branch since last common ancestor with another branch

A

git diff «old branch»..«new branch»
git diff ^«old branch» «new branch»
git diff «new branch» –not «old branch»

142
Q

restore last saved uncommitted work in git and delete entry

A

git stash pop

143
Q

restore older than last saved uncommitted work in git and delete entry

A

git stash pop «stash number»

144
Q

show differences between last saved uncommitted work and preceding git commit

A

git stash show

145
Q

show differences between older than last saved uncommitted work and preceding git commit

A

git stash show «stash number»

146
Q

create git branch from older than last saved uncommitted work

A

git stash branch «branch» «stash number»

147
Q

find common ancestor of two git branches

A

git merge-base «branch1» «branch2»

148
Q

interactively rebase current git branch on top of another base branch?

A

git rebase -i «base branch»

149
Q

undo last git commit

A

git reset –soft HEAD^

150
Q

redo last git commit (after undoing it) and edit commit message

A

(git reset –soft HEAD^)

git commit -a -c ORIG_HEAD

151
Q

redo last git commit (after undoing it) with the old commit message

A

(git reset –soft HEAD^)

git commit -a -C ORIG_HEAD

152
Q

reset file in workspace back by «X» git commits

A

git checkout HEAD~«X» «file»

153
Q

add or reset workspace file from another git commit

A

git checkout «commit» «file»

154
Q

reset git staging area to last commit

A

git reset

155
Q

clear staging area of git project with submodule(s)

A

git submodule foreach ‘git stash’

156
Q

initialize and push local project to github

A
» create new GitHub repository (without readme)
» git init
» git add .
» git commit -m 'First commit'
» git remote add origin «repository url»
» git push -u origin master
157
Q

remove folder from git only

A

git rm –cached -r «folder»

» -r stands for recursive

158
Q

add and commit all new changes in git

A

git commit -am ‘«commit message»’