Another Git cheat sheet yet
- Configuration
- Commiting
- Branching
- Pulling
- Pushing
- Logging
- Tagging
- Reflog
- Resolve conflicts
- Aliases
- Bonus
- Resources
git config user.name "Name"
git config user.email '<name@email.com>'
Tip: Add --global flag for global config.
List your gpg keys:
gpg --list-secret-keys --keyid-format LONG
/Users/username/.gnupg/secring.gpg
------------------------------------
sec 4096R/2AA5B24170567CE0 2019-01-01 [expires: 2020-01-01]
Tip: For a GPG key setup check out Generating a new GPG key
Add your GPG signing key in Git globally:
git config --global user.signingkey 2AA5B24170567CE0
Tip: For disable signing commits temporarily try: git config --global commit.gpgsign false
git config --global core.excludesfile ~/.gitignore
git remote add <remote_origin> <repo_url>
git remote remove <remote_origin>
git status
Tip: Use -sb
flag to see the status in a compact way.
git add <some_files_or_directories>
Tips: Use a dot git add .
to stage all files for commit.
git commit <some_files_or_directories>
Tips: Add -m "Message here"
to commit with a message directly.
git commit --amend
Tip: Add --author="Name <name@email>"
to override author.
git reset HEAD^
Caution: This command throws away all your uncommitted changes. For safety, you should always check that the output of git status
is clean (that is, empty) before using it. See this thread for more details.
git reset --hard HEAD
Cherry pick means to choose a commit from one branch and apply it onto another. See this thread for more details.
git cherry-pick <other_branch_parent_commit> -m 1
Note: Parent number starting from 1. See this thread for more details.
git cherry-pick $(git rev-parse <other_branch_name>) -m 1
git checkout -b <new_branch>
git checkout -tb <local_branch> origin/<remote_branch>
git branch -m <new_branch_name>
Tip: Use -M
flag to forcing instead.
git branch -a
git branch -r
git branch -d <branch_name_1> <branch_name_2> <branch_name_n>
Tip: Tip: Use -D
flag to forcing instead.
git checkout <target_branch>
git merge <source_branch>
Tip: Add --squash
flat for a squash merging.
This command makes this for you:
- Save your uncommitted changes locally with
git stash
. - Local changes you made will be rebased on top of the remote changes.
- Return your uncommitted changes locally again.
git pull <remote_origin> <target_branch> --rebase --autostash
Tip: Skip --rebase
if you want to merge your changes with the remote changes.
git push <remote_origin> <branch_name>
git log -1 HEAD
git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
git tag v1.0.0
git tag -d v1.0.0
git reflog
TODO
If you don't want to type the entire text of each of the Git commands above, you can easily set up an alias for each command and then just run it.
Example: We will create an alias last
that shows log info of the last commit.
git config --global alias.last 'log -1 HEAD'
Then just run:
git last
- git-useful-aliases — Set of useful Git aliases.
- GitNow — Speed up your Git workflow.
- https://git-scm.com/docs
- https://github.com/nvie/gitflow
- https://github.com/jakubpawlowicz/git-cheat-sheet
- https://github.com/git-tips/tips
- https://github.com/razzius/git-tricks
Feel free to send some Pull request or issue.
To the extent possible under law, Jose Quintana has waived all copyright and related or neighboring rights to this work.