Git Cheat sheet
Article Info
- Last Updated
- (c1e71b8)
- Tags
- Cli
Git has many command line flags and is a very verstile program. If you want the complete guide, consult the Git Book. This page outlines some common commands and what they do.
Getting New Code
Commands for getting existing repositories.
Command | Effect | Example |
---|---|---|
git clone <repo> |
create a copy of a repository from elsewhere | git clone example.com/repos/example.git |
git init |
create a new empty repository | git init |
Day-To-Day Git
Here are the ‘day to day’ commands you are likely to use with Git:
Command | Effect | Example |
---|---|---|
git pull |
Get changes from a remote server | git pull |
git push |
Send changes to a remote server | git push |
git add <pathspec> |
Stage files for commit | git add . |
git restore <pathspec> |
Unstage files for commit | git restore . |
git commit -m <message> |
Create a new git commit | git commit -m ‘i changed things’ |
git status |
See unstaged and staged changes | git status |
git log |
See the commit history | git log |
Branches
Commands useful for branch-based workflows.
Command | Effect | Example |
---|---|---|
git checkout |
Swap between branches1 | git checkout develop |
git branch |
See existing branches | git branch |
git checkout -b <branch> |
Create and swap to a new branch called <branch> 1 |
git checkout -b develop |
1 requires clean working state
Useful Resources
Here are some useful resources from the web: