Yet another Git cheat sheet?
Just for the commands I use often…
Clone repositories and create new branches
Start own copy of repository:
git clone <url>
See branches:
git branch
Change to a different branch:
git checkout <branch-name>
Create new branch from existing branch:
git checkout -b <new-branch-name> <existing-branch-name>
Push new branch to remote repository:
git push origin <branch-name>
Submit changes
See actual branch and changes to commit
git status
Add new file to Index
git add <filename>
Commit changes to Head
git commit -m "Commit message"
Push changes to remote repository
git push origin <branch-name>
Merge
Merge two branches - e.g. update
git merge <branch-name>
Revert merge
git revert -m 1
Working with a remote repository and an upstream repository
Get changes from remote repository
git pull origin
Merge changes in master to my branch
git checkout master
git pull origin
git checkout my-branch
git merge master
Getting changes from upstream repository (i.e. from which you forked)
1) Define upstream
git remote add upstream https://github.com/<original>
git remote -v # to see the changes
2) Switch to master
git checkout master
3) Fetch upstream data
git fetch upstream
4) Merge into fork’s master
git merge upstream/master
5) Push changes
git push origin master