Git Cheat Sheet

This is a simple Git cheat sheet. Most usage Git command lines are included.

Basic workflow

git initcreate new repository
git clone /path/to/repositoryclone local repository
git clone [email protected]:/path/to/repositoryclone remote repository
git add <filename>add changes of a file
git add *add all changes
git rm <filename>delete a file
git commit -m *<comment>*commit changes
git push origin nasterpush changes to remote repository
git remote add origin <server>connect local repository to remote one
git pullupdate local repository with remote one

Branches

git branchList all local branches
git branch -aList remote and local branches
git checkout -b <branch_name>Create a new local branch and switch to it
git checkout <branch_name>Switch to a branch
git push origin <branch_name>Push a branch to remote
git branch -m <new_brand_name>Rename a branch
git branch -d <branch_name>Delete a local branch
git push origin <branch_name>Delete a remote branch

Clean up

git clean -fDelete all untracked files
git clean -dfDelete all untracked files and directories
git checkout -- .Undo local modifications to all files
git reset HEAD <filename>Unstage a file

Stash

git stash save "<stash_name>" && git stashSave changes to a stash
git stash listList all available stashes
git stash popDelete a stash from the list

Log

git log --onelineShow commit history in single lines
git log -10Show commit history for last 10 commits
git log -p -10Show commit history for last 10 commits with diff
git diffShow all local file changes in the working tree
git diff <filename>Show changes made to a file
git blame <filename>Show who modified a file
git remote show originShow remote branches and their mapping to local

Leave a Comment

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

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close