Git Cheatsheet

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Git Cheatsheet

Standard workflow
 git pull – pulls any changes in the remote repository to your local repository
 git add [files] – adds files to staging area
 git commit –m [message] – adds files in staging area to a local repository
 git push – pushes local repository changes to remote repository

Useful commands:
 git status – look at the status of your local repository in terms of which files
have been modified since last commit, list the branch you are on, etc
 git log – list all commits, local and remote. Each commit has a hash, which is
a string of alpha-numeric characters, which represents a unique ID. This
commit ID can be used in conjunction with “git checkout [commit id]” to
revert your local repository to the file system status at the time of that
commit
 git stash – store your local changes in the stash. Can be named and restored
with git stash pop
 git clone [url] – clone a fresh copy of a remote repository

Branching:
 git checkout [branch name] – switches your current branch to the specified
branch
 git branch [branch name] – creates a new branch with the specified name
 git push origin [branch name] – push the changes in your local repository to
the specified branch, regardless of the branch you are on
 git pull origin [branch name] – pulls the changes of the specified branch
into your local repository

When merging:
 git merge abort – Use this when you get merge conflicts and you don’t want
to merge. This command reverts the state of your local repository to that of
the repository just before a pull – this is only applicable if you receive merge
conflicts. Useful if you want to give up on merging and simply take
 git checkout –theirs [filename] – use this when merging if you wish to
ignore the changes you have made to a particular file, and simply take all
changes the remote has. git checkout –yours is also an option.
Troubleshooting:
 git reset –-hard – Use this command if your repository is messed up and
you want to just delete all changes. You can specify a commit id in the form
git reset –-hard [commit id] to revert to a specific commit (you can see the
commit ids via git log)

You might also like