GitKraken in commands

Anh-Thi Dinh
Here are the terminal commands you can use instead of Gitkraken . This note is for situations where GitKraken isn't available. For a full list of git commands, refer to this note: Git!
Clone a repo
1git clone <repo-link>
2# or using gh
Check status (what are in stage or unstage)
1git status
Show list of commits
1# local, current branch
2git log --graph --decorate --oneline
3# press "q" to quit
4
5# remote branch b1 (local may have different commits)
6git fetch origin
7git log origin/b1 --graph --decorate --oneline
Working with branches
1# Create a new branch from a commit
2git checkout -b <new_branch_name> <commit_hash>
3
4# Create a new branch based on another branch
5git checkout -b <new_branch_name> <existing_branch_name>
6
7# push to remote
8git push -u origin <new_branch_name>
9
10# force to push
11git push origin <branch-name> -f
12
13# Rename currently local branch
14git branch -m <new_branch_name>
15
16# Rename any local branch
17git branch -m old_branch new_branch
18
19# Verify branch
20git branch
21# remote
22git branch -r
23
24# Push renamed branch to remote and delete the old one on remote
25git push origin -u new_branch
26git push origin --delete old_branch
27
28# Remove a local branch
29git branch -d branch_name
30# force
31git branch -D branch_name
32
33# Remove a remote branch
34git push origin --delete branch_name
35
Stage and unstage
1# Stage File
2git add <file>
3
4# Stage multiple files
5git add <file_1> <file_2>
6
7# Stage All Changes
8git add .
9
10# Unstage File
11git restore --staged <file>
12# or
13git reset <file>
14
15# Unstage All Changes
16git reset
Discard changes (don’t apply for newly created files)
1# Discard changes in a file
2git restore <file>
3
4# Discard all changes (unstaged)
5git restore .
6
7# Discard all staged and unstaged
8git reset --hard
Pull
1# Fetch All
2git fetch --all
3
4# fast-forward (if possible) <- it will perform a merge after the pull
5git pull --ff
6
7# fast-forward only (only pull, not merge)
8git pull --ff-only
9
10# rebase <- move all local changes on top of the remote changes
11git pull --rebase
Rebase
1# Rebase current branch (b1) onto (dev)
2git rebase dev
3
4# If there are conflicts -> modify manually and then
5git add file_name
6git rebase --continue
7
8# Abort the rebase
9git rebase --abort
10
11# Force push b1 after the rebase
12git push origin b1 --force
Merge
1# Merge current branch (b1) into (dev)
2git checkout dev
3git merge b1
4
5# If there are conflicts -> modify manually and then
6git add file_name
7git commit
8
9# Check the commit history
10git log --graph --decorate --oneline
Stash and Pop
1# Stash (temporarily stash all local changes and pop them later)
2git stash push -u # "-u" stash also untracked files
3
4# Pop
5git stash pop
6
7# Pop a specific
8git stash pop stash@{N} # use `git stash list` to check all stashes
9
10# See list of all stashes
11git stash list
12
13# Apply stash (just apply the stashed, keep the stash in the list)
14git stash apply
15
16# apply a specific stash
17git stash apply stash@{N}
Squash
1# Squash N latests commits & put all commit messags to description
2git reset --soft HEAD~3 && 
3git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"
Reset current branch to a commit
1# Soft - keep all changes
2# (all files in the commits that come after the chosen commit 
3# will be kept as staged, all unstaged changes will be kept as they are)
4git reset --soft commit_hash
5
6# uncommit (undo the recent commit)
7git reset --soft HEAD~1
8
9# Hard - discard all changes
10git reset --hard <commit_hash>
11
12# Mixed - keep working copy and reset index
13# (all files in commits that come after the chosen commit 
14# will be kept as unstaged, all unstaged changes will be kept as they are)
15git reset --mixed <commit_hash>
Revert commit (it reverts only the changes made by the chosen commit, all changes come after will be kept)
1git revert <commit>
Checkout a commit (temporarily move to a commit)
1git checkout <commit>
2# after inspecting, return to your branch
3git checkout <branch>
Tag
1# create a tag at a specific commit
2git tag tag_name commit_hash
3# annotated
4git tag -a tag_name commit_hash -m "messages"
5
6# push tag to remote
7git push origin tag_name
8
9# remove a tag locally
10git tag -d tag_name
11
12# remove a tag from the remote
13git push origin --delete tag_name
Cherry pick commit
1# cherry pick a commit to the current branch
2git cherry-pick <commit hash>
3
4# to another branch
5git checkout another_branch
6git cherry-pick commit_hash
7
8# resolve conflicts if any
9git add file_name
10git cherry-pick --continue
11# abort?
12git cherry-pick --abort
to be continued…