Git Flashcards

(158 cards)

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
show all git commits without merge commits
git log --no-merges
26
change git commit message | add or update files of last commit
git commit --amend » overwrites commit with current staging area
27
unstage file in git
git reset «file» git restore --staged «file» *git unstage «file»
28
reset file in workspace to status of last git commit
git checkout -- «file»
29
what is the difference between git fetch and git pull?
pull = fetch + merge
30
change name of git remote
git remote rename «old name» «new name»
31
what additional information does an annotated git tag contain apart from tag name?
» tagger email » tag date » tag message
32
create lightweight git tag
git tag «tag name»
33
create annotated git tag with a message
git tag -a «tag name» -m «commit message»
34
put leightweight tag on existing git commit
git tag «commit» «tag name»
35
upload specific git tag on the remote
git push «remote» «tag name»
36
delete local git tag
git tag -d «tag name»
37
delete branch on git remote
git push «remote» --delete «remote branch» git push «remote» -d «remote branch» git push «remote» :«remote branch»
38
create alias for git command
git config --global alias.«alias name» '«git command»'
39
show all git commits of specific branch
git log «local branch»
40
show all git commits of all branches
git log --all
41
delete local git branch
git branch -d «local branch»
42
how does 'git merge «branch»' work?
» tries to merge «branch» into current branch If the merge fails: » resolve merge conflicts » stage resolved files » complete with 'git commit'
43
show all merged in git branches
git branch --merged
44
show all not yet merged in git branches
git branch --no-merged
45
update local cache of specific git remote
git fetch «remote» » new remote branches don't create local copies
46
push git branch to specific remote branch
git push «remote» «local branch»:«remote branch»
47
create, name and switch to branch and track specific remote git branch
git switch -c «local branch» «remote»/«remote branch» | git checkout -b «local branch» --track «remote»/«remote branch»
48
create, name and switch to branch and do not track any remote branch
git switch -c «branch» --no-track | git checkout -b «branch» --no-track
49
set or update the current git branch's tracking to specific remote branch
git branch -u «remote»/«remote branch»
50
get git remote tracking status of all branches
git fetch --all; git branch -vv
51
rebase git branch onto another branch
git rebase «base branch» «head branch»
52
add file removal(s) to git staging area
git add «file 1» («file 2 «file 3»)
53
push a rebased git branch to remote
git push «remote» «local branch» --force-with-lease
54
merge in whole git branch as a commit
git merge --squash «local branch»
55
do one time git pull by url
git pull «remote url»
56
show git commits of one branch since last common ancestor with another branch
git log «old branch»..«new branch» git log ^«old branch» «new branch» git log «new branch» --not «old branch»
57
show git commits of both branches since last common ancestor with another branch
git log «branch 1»...«branch 2»
58
show git commits with short hashes
git log --abbrev-commit
59
show a git commit's details
git show «commit»
60
show a git commit parent's details
git show «commit»^
61
enter interactive git staging
git add -i
62
partially add git file
git add -p «file»
63
save current work on tracked files without git commit and reset workspace
git stash
64
restore last saved uncommitted work in git
git stash apply
65
restore older than last saved uncommitted work in git
git stash apply «stash number»
66
show all saved uncommitted work in git
git stash list
67
restore last saved uncommitted work and git staging
git stash apply --index
68
save current work on tracked files without git commit but keep the git staging and reset workspace
git stash -k
69
save current work without git commit including untracked files and reset workspace
git stash -u
70
save current work without git commit including untracked and explicitly ignored files and reset workspace
git stash -a
71
partially save parts of current work without git commit and reset workspace
git stash -p
72
create git branch from last saved uncommitted work
git stash branch «branch name»
73
show git history of a specific function in s specific file
git log -L :«function name»:«specific file»
74
add or update files of last git commit without changing commit message
git commit --amend --no-edit » overwrites commit with current staging area
75
interactively rewrite git history of last «X» commits
git rebase -i HEAD~«X»
76
reset branch to a specific git commit and clear staging area
git reset «commit» » keeps workspace
77
reset branch to a specific git commit and put newer commit contents in staging area
git reset --soft «commit» » keeps workspace
78
reset branch and workspace to a specific git commit and clear staging area
git reset --hard «commit» » risk of loosing data (!)
79
add or reset file in staging area from another git commit
git reset «commit» -- «file»
80
what does the git -- option mean?
do not interpret any more command arguments as options
81
cancel a merge in git
git merge --abort
82
merge and ignore git whitespace issues
git merge -Xignore-all-space » ignores whitespaces completely ------------ git merge -Xignore-space-change » treats one ore more whitespace characters as equivalent
83
merge in a file from another git commit or branch
git checkout «commit/branch» «file»
84
reset a file's git merge conflict markers
git checkout --conflict «file»
85
reset and show details of a file's git merge conflicts
git checkout --conflict=diff3 «file»
86
solve git merge conflict by choosing the file's workspace version
git checkout --ours «file»
87
solve git merge conflict by choosing the file's merge branch version
git checkout --theirs «file»
88
show log of full git merge
git log --oneline --left-right HEAD...MERGE_HEAD
89
show log of git merge conflict commits
git log --oneline --left-right --merge
90
show log of git merge conflict differences
git log --oneline --left-right -p
91
undo a git commit by doing another cancelling commit
git revert «commit to undo»
92
fake the git merge of another branch into current branch
git merge -s ours «incoming branch»
93
show git history of a file's line range
git blame -L «from line»,«to line» «file»
94
show git history of a file including line movements from other files
git blame -C «file»
95
how tu use git binary search to find erroneous commit
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
add git submodule from URL
git add submodule «submodule url»
97
download a git repository including all submodules (and all their submodules)
``` 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
update all git submodules from it's remote tracking
git submodule update --remote » puts submodule into detached HEAD state
99
update a specific git submodule it's remote tracking
git submodule update --remote «submodule»
100
set a git submodule's tracking branch
git config -f .gitmodules submodule.«submodule name».branch «remote tracking branch»
101
update git submodule (and their submodule) after pull from superproject
``` (git pull) git submodule update --init (--recursive) ```
102
update git submodule from it's remote keeping our changes
``` cd «submodule folder» git checkout «new branch» cd .. (back into superproject folder) ``` git submodule update --remote --merge/rebase - ------------------ * git supdate
103
upload local changes of git submodule
cd «submodule folder» git push ------------------- git push --recurse-submodules=on-demand » tries to push submodule before pushing superproject - ------------------ * git spush
104
create new git branch of project with submodule(s)
git submodule foreach 'git switch -c «branch»'
105
show differences between git staging area and workspace including submodules
git diff git submodule foreach 'git diff' ------------------- *git sdiff
106
set git config variable
git config (--global) «setting» «value»
107
create git bundle file of a commit range and name it
git bundle create «file name».bundle «head commit» ^«base commit» git bundle create «file name».bundle «base commit»..«head commit»
108
create git bundle file of the whole branch and name it
git bundle create «file name».bundle HEAD «branch»
109
check if git bundle is valid
git bundle verify «file name»
110
create new git branch
git branch «branch name»
111
create new git branch based on a commit
git branch «branch name» «commit»
112
show all git tags
git tag
113
show all configured git aliases
git config --list | grep alias
114
show last git commit
git log -1 HEAD | *git last
115
upload a local branch to the git remote
git push «remote» «local branch»
116
upload all local branches to the git remote
git push --all «remote»
117
upload a local branch to a specific branch of the git remote
git push «remote» «local branch»:«remote branch»
118
upload a local branch to the git remote and save as remote tracking default
git push -u «remote» «local branch» » «remote» and «local branch» can be omitted from now on
119
stage all file modifications and deletions in git
git add -u
120
stage all file modifications, new files and deletions in git
git add -A
121
update local branch cache of this branch's git remote
git fetch » new remote branches don't create local copies
122
show not yet merged in branches into specific git branch
git branch --merged
123
show merged in branches into specific git branch
git branch --no-merged
124
rebase current branch on top of another base git branch?
git rebase «base branch»
125
update local cache of all git remotes and remove outdated branch trackings
git fetch --prune
126
remove folder from git and delete folder from workspace
git rm -r «folder»
127
remove folder from git and delete folder from workspace
git rm -r «folder»
128
update all new git tags on the remote
git push «remote» --tags
129
delete tag on git remote
git push «remote» --delete «tag name» git push «remote» -D «tag name» git push «remote» :«tag name»
130
update local cache of all git remotes
git fetch --all » new remote branches don't create local copies
131
update local cache of a specific git remote's branch
git fetch «remote» «remote branch»
132
switch back to previous git branch
git switch -
133
create, switch to and do not track local copy of a specific git remote's branch
git switch -c --no-track «remote»/«remote branch» | git checkout -b «remote»/«remote branch»
134
create, switch to and track local copy of a specific git remote's branch
git switch --track «remote»/«remote branch» | git checkout --track «remote»/«remote branch»
135
create branch based on a git commit
git switch -c «branch» «commit»
136
switch to git commit and detach from HEAD for temporary inspection
git switch --detach «commit» | git checkout «commit»
137
create and track local copy of remote git branch and switch to it
git switch «remote branch» | git checkout «remote branch»
138
set or update another local branch's git tracking to a specific remote branch
git branch -u «remote»/«remote branch» «local branch»
139
unite last «X» git commits to one
git reset --soft HEAD~«X»; git commit
140
show all git commit's details since last common ancestor of two branches
git diff --left-right «branch 1»...«branch 2»
141
show git commit's details of a branch since last common ancestor with another branch
git diff «old branch»..«new branch» git diff ^«old branch» «new branch» git diff «new branch» --not «old branch»
142
restore last saved uncommitted work in git and delete entry
git stash pop
143
restore older than last saved uncommitted work in git and delete entry
git stash pop «stash number»
144
show differences between last saved uncommitted work and preceding git commit
git stash show
145
show differences between older than last saved uncommitted work and preceding git commit
git stash show «stash number»
146
create git branch from older than last saved uncommitted work
git stash branch «branch» «stash number»
147
find common ancestor of two git branches
git merge-base «branch 1» «branch 2»
148
interactively rebase current git branch on top of another base branch?
git rebase -i «base branch»
149
undo last git commit
git reset --soft HEAD^
150
redo last git commit (after undoing it) and edit commit message
(git reset --soft HEAD^) | git commit -a -c ORIG_HEAD
151
redo last git commit (after undoing it) with the old commit message
(git reset --soft HEAD^) | git commit -a -C ORIG_HEAD
152
reset file in workspace back by «X» git commits
git checkout HEAD~«X» «file»
153
add or reset workspace file from another git commit
git checkout «commit» «file»
154
reset git staging area to last commit
git reset
155
clear staging area of git project with submodule(s)
git submodule foreach 'git stash'
156
initialize and push local project to github
``` » 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
remove folder from git only
git rm --cached -r «folder» » -r stands for recursive
158
add and commit all new changes in git
git commit -am '«commit message»'