Web-Dev-Hub-Docs
Web Development Frameworks & Libraries
Productivity
Misc
Backend
Networking
Science & Tech (Innovation)
Reading
Docs
Code Editors & Tools
Free-Stuff
Blockchain & Crypto
Data Structures & Interviewing
WEBDEV-Bootcamp-Notes
Group 1
Powered By GitBook
Git-Tricks
Refs
​

Awesome GitHub Commands Reference Sheet (Quick Reference)

1
HEAD^ # 1 commit before head
2
HEAD^^ # 2 commits before head
3
HEAD~5 # 5 commits before head
Copied!

Branches

1
# create a new branch
2
git checkout -b $branchname
3
git push origin $branchname --set-upstream
4
​
5
# get a remote branch
6
git fetch origin
7
git checkout --track origin/$branchname
8
​
9
# delete local remote-tracking branches (lol)
10
git remote prune origin
11
​
12
# list merged branches
13
git branch -a --merged
14
​
15
# delete remote branch
16
git push origin :$branchname
17
18
# go back to previous branch
19
git checkout -
Copied!

Collaboration

1
# Rebase your changes on top of the remote master
2
git pull --rebase upstream master
3
4
# Squash multiple commits into one for a cleaner git log
5
# (on the following screen change the word pick to either 'f' or 's')
6
git rebase -i $commit_ref
Copied!

Submodules

1
# Import .gitmodules
2
git submodule init
3
​
4
# Clone missing submodules, and checkout commits
5
git submodule update --init --recursive
6
​
7
# Update remote URLs in .gitmodules
8
# (Use when you changed remotes in submodules)
9
git submodule sync
Copied!

Diff

Diff with stats

1
git diff --stat
2
app/a.txt | 2 +-
3
app/b.txt | 8 ++----
4
2 files changed, 10 insertions(+), 84 deletions(-)
Copied!

Just filenames

1
git diff --summary
Copied!

Log options

1
--oneline
2
e11e9f9 Commit message here
3
​
4
--decorate
5
shows "(origin/master)"
6
​
7
--graph
8
shows graph lines
9
​
10
--date=relative
11
"2 hours ago"
Copied!

Misc

Cherry pick

1
git rebase 76acada^
2
​
3
# get current sha1 (?)
4
git show-ref HEAD -s
5
​
6
# show single commit info
7
git log -1 f5a960b5
8
​
9
# Go back up to root directory
10
cd "$(git rev-parse --show-top-level)"
Copied!

Short log

1
$ git shortlog
2
$ git shortlog HEAD~20.. # last 20 commits
3
​
4
James Dean (1):
5
Commit here
6
Commit there
7
​
8
Frank Sinatra (5):
9
Another commit
10
This other commit
Copied!

Bisect

1
git bisect start HEAD HEAD~6
2
git bisect run npm test
3
git checkout refs/bisect/bad # this is where it screwed up
4
git bisect reset
Copied!

Manual bisection

1
git bisect start
2
git bisect good # current version is good
3
​
4
git checkout HEAD~8
5
npm test # see if it's good
6
git bisect bad # current version is bad
7
​
8
git bisect reset # abort
Copied!

Searching

1
git log --grep="fixes things" # search in commit messages
2
git log -S"window.alert" # search in code
3
git log -G"foo.*" # search in code (regex)
Copied!

GPG Signing

1
git config set user.signingkey <GPG KEY ID> # Sets GPG key to use for signing
2
​
3
git commit -m "Implement feature Y" --gpg-sign # Or -S, GPG signs commit
4
​
5
git config set commit.gpgsign true # Sign commits by default
6
git commit -m "Implement feature Y" --no-gpg-sign # Do not sign
7
---
Copied!

Refs

1
HEAD^ # 1 commit before head
2
HEAD^^ # 2 commits before head
3
HEAD~5 # 5 commits before head
Copied!

Branches

1
# create a new branch
2
git checkout -b $branchname
3
git push origin $branchname --set-upstream
4
​
5
# get a remote branch
6
git fetch origin
7
git checkout --track origin/$branchname
8
​
9
# delete local remote-tracking branches (lol)
10
git remote prune origin
11
​
12
# list merged branches
13
git branch -a --merged
14
​
15
# delete remote branch
16
git push origin :$branchname
17
18
# go back to previous branch
19
git checkout -
Copied!

Collaboration

1
# Rebase your changes on top of the remote master
2
git pull --rebase upstream master
3
4
# Squash multiple commits into one for a cleaner git log
5
# (on the following screen change the word pick to either 'f' or 's')
6
git rebase -i $commit_ref
Copied!

Submodules

1
# Import .gitmodules
2
git submodule init
3
​
4
# Clone missing submodules, and checkout commits
5
git submodule update --init --recursive
6
​
7
# Update remote URLs in .gitmodules
8
# (Use when you changed remotes in submodules)
9
git submodule sync
Copied!

Diff

Diff with stats

1
git diff --stat
2
app/a.txt | 2 +-
3
app/b.txt | 8 ++----
4
2 files changed, 10 insertions(+), 84 deletions(-)
Copied!

Just filenames

1
git diff --summary
Copied!

Log options

1
--oneline
2
e11e9f9 Commit message here
3
​
4
--decorate
5
shows "(origin/master)"
6
​
7
--graph
8
shows graph lines
9
​
10
--date=relative
11
"2 hours ago"
Copied!

Miscellaneous

Cherry pick

1
git rebase 76acada^
2
​
3
# get current sha1 (?)
4
git show-ref HEAD -s
5
​
6
# show single commit info
7
git log -1 f5a960b5
8
​
9
# Go back up to root directory
10
cd "$(git rev-parse --show-top-level)"
Copied!

Short log

1
$ git shortlog
2
$ git shortlog HEAD~20.. # last 20 commits
3
​
4
James Dean (1):
5
Commit here
6
Commit there
7
​
8
Frank Sinatra (5):
9
Another commit
10
This other commit
Copied!

Bisect

1
git bisect start HEAD HEAD~6
2
git bisect run npm test
3
git checkout refs/bisect/bad # this is where it screwed up
4
git bisect reset
Copied!

Manual bisection

1
git bisect start
2
git bisect good # current version is good
3
​
4
git checkout HEAD~8
5
npm test # see if it's good
6
git bisect bad # current version is bad
7
​
8
git bisect reset # abort
Copied!

Searching

1
git log --grep="fixes things" # search in commit messages
2
git log -S"window.alert" # search in code
3
git log -G"foo.*" # search in code (regex)
Copied!

GPG Signing

1
git config set user.signingkey <GPG KEY ID> # Sets GPG key to use for signing
2
​
3
git commit -m "Implement feature Y" --gpg-sign # Or -S, GPG signs commit
4
​
5
git config set commit.gpgsign true # Sign commits by default
6
git commit -m "Implement feature Y" --no-gpg-sign # Do not sign
Copied!
​
#### If you found this guide helpful feel free to checkout my github/gists where I host similar content:
Or Checkout my personal Resource Site:
​Canonical link​
Exported from Medium on August 31, 2021.
Last modified 1d ago