Git Cheatsheet
Useful snippets
Enable autocomplete on tab for Git branches
To enable auto completion for Git branch names; enter these two lines into your terminal (press return after each), then restart your terminal. Now, when you're typing a branch name, you can begin to type, then hit tab, and terminal will autocomplete the branch name, saving you time and reducing the chance for typos.
echo 'autoload -Uz compinit && compinit' >> ~/.zshrc
source ~/.zshrc
Common Git Commands
Clone repository
git clone [repo url]
Create branch
git branch [branch-name]
Create branch and switch to it
git checkout -b [branch-name]
Checkout existing branch
git checkout [branch-name]
Delete branch
git branch -d [branch-name]
Update remote branches
git fetch
Pull changes of current branch
git pull
Merge another branch into your current branch
git merge [branch-name] -m “[commit message]”
View pending changes
git status
Stage one file
git add [file-name]
Stage hunk of file
git add -p [file-name]
Stage everything
git stage .
Commit changes
git commit -m “[commit message]”
Push changes
git push
List branches
git branch