Using CheatSheets To Apply Best Practices

Git CheatSheet

Git CheatSheet


PRs Welcome

File me Issues or star this repo.

See more CheatSheets from Denny: #denny-cheatsheets

1.1 Git General

Name Comment
List all remote git branches git ls-remote --heads origin
Git diff two revision git diff ${sha1sum}..${sha2sum}
Git show file changes git diff --name-only ${sha1sum} ${sha2sum}
Show git config git config --global/system

1.2 Git Commit

Name Comment
Git squash to make history clean git rebase -i HEAD~4; git push origin <branch-name> --force link
Git commit and squash git commit --amend --no-edit, git push origin <branch-name> --force
Git add patch git add -p
Git commit git commit -m "XXX"
Git add and commit git ci -m "XXX"

1.3 Git Diff

Name Comment
Compare git diff after commit git diff --cached
Show changed file list git diff --name-status, git diff --name-status --cached
Compare two branches in CLI git diff <branch_1>..<branch_2> Make sure you have those branches locally
Compare two revision in GitHub UI…/…/compare/sha1…sha2
Compare latest 3 commits in GitHub UI…HEAD
Configure default editor export pager=cat

1.4 Git Tag

Name Comment
Git list all tags git ls-remote --tags
Git Fetch all tags git fetch --tags; git checkout tags/<tag_name>
Git delete local tag git tag -d <tag_name>
Git delete remote tag git push --delete origin <tag_name>

1.5 Git Branch

Name Comment
Show remote branch git ls-remote --heads origin
Delete local branch git branch -d <branch_name>
Delete remote branch git push origin --delete <branch_name>

1.6 Git alias

Name Comment
Alias for git status git config --global status Link: git aliases
Alias for git checkout git config --global checkout
Alias for git commit git config --global commit

1.7 Git Submodule

Name Comment
Git add a repo to current repo git submodule add <git_repo_url>
Update submodule git submodule update

1.8 git remote repo

  • Configure two remote endpoint
git clone

git config remote.origin2.url
git config remote.origin.url

git pull origin2 sprint-37

## File: .git/config
## ,-----------
## | [core]
## |    repositoryformatversion = 0
## |    filemode = true
## |    bare = false
## |    logallrefupdates = true
## |    ignorecase = true
## |    precomposeunicode = true
## | [remote "origin"]
## |    url =
## |    fetch = +refs/heads/*:refs/remotes/origin/*
## | [branch "master"]
## |    remote = origin
## |    merge = refs/heads/master
## | [remote "origin2"]
## |    url =
## |    fetch = +refs/heads/*:refs/remotes/customer/*
## `-----------

1.9 GitHub

Name Comment
Generate link for a code block link
Git clone wiki link
Generate TOC gh-md-toc
Github Shortcut link
  • GitHub/GitLab markdown image size
<img src="images/pks_logging_components.png" width="700x">

<img src="/uploads/d19fcc3d3b4d313c8cd7960a343463b6/table.png"  width="120" height="120">

![](./pic/pic1_50.png =100x20)
You can skip the HEIGHT

![](./pic/pic1s.png =250x)

1.10 More Resources

License: Code is licensed under MIT License.


Leave a Reply

Your email address will not be published. Required fields are marked *