A useful reference list of Git Bash commands. If there's something missing, please add it!
Command | Description |
---|---|
git config --global user.email <email address> | set email |
git config --global user.name <name> | set username |
ssh-keygen -t rsa -b 4096 -C "email address" | create ssh key |
cd | change directory |
ls | list contents of current directory |
git clone <repo key from GitHub> | clone directory |
git status | tells you what branch you are on, what commits have been made and any changes made to files |
git add . | stages every file where a change has been made (not really recommended as general good practice) |
git add . –n | shows what would be committed but doesn’t carry out any action |
git add <file> | stages changes made to a particular file |
git rm –cached <file> | to unstage a file |
git commit –m “Commit message” | commit staged changes |
git push | push commits to GitHub |
git pull | pulls from GitHub |
git branch | tells you what branch you are on |
git branch <feature/post_name> | create new branch locally |
git checkout <branch> | change to branch |
git checkout –b <feature/post_name> | create new branch locally and change to it |
git push origin <feature/post_name> -u | create branch on GitHub |
git log --oneline --graph --decorate --all | creates a neat little summary of the branch history of the repo |
git branch –d <feature/post_name> | delete branch locally |
git diff <feature/post_name> | view diff of unstaged file |
git revert -n <commit reference> | stage new commit to reverse changes made in referenced commit |
git reset --mixed <commit reference> | delete commits since the referenced commit but retain changes (unstaged) |
git reset --hard <commit reference> | delete commits since the referenced commit and remove all changes from files |
git reset --soft <commit reference> | delete commits since the referenced commit but retain changes (staged) |
git commit --amend -m "commit message" | amend last commit message |