Last active
August 29, 2015 14:02
-
-
Save Bekt/5f36224899bb951f39aa to your computer and use it in GitHub Desktop.
Git 101
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a Git cheat-sheet for beginners. | |
# 1. Initial clone | |
git clone <package name> | |
# 2. Checkout a new branch | |
git checkout -b <feature> | |
# 3. Make changes | |
echo "Hack hack hack" >> newfile.txt | |
# 4. Commit | |
git add --all | |
git commit -m "Added a new file." | |
# 5. Submit for a code review (optional) | |
post-review --parent=master | |
# 6. Make more changes (e.g based on code review comments) | |
echo "Moar changez" >> newfile.txt | |
# 7. Append new changes to previous commit | |
git add --all | |
git commit --amend --no-edit | |
# 8. Switch back to master and sync | |
git checkout master | |
git pull | |
# 9. Switch to <feature> branch and rebase | |
git checkout <feature> | |
git rebase master | |
# 10. Reflect the <feature> changes in the master | |
git checkout master | |
git merge <feature> | |
# 11. Push master to the remote | |
git push | |
# 12. Delete the local <feature> branch | |
git branch -d <feature> | |
# 13. Back to step 2 to work on a new feature |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here are some that I have been using everyday. I do QA and review code and apply some patches if necessary.
checkout remote branch and create a local copy of the branch
git checkout -b local_branch_name remote/branch_name
checkout remote branch
git checkout remote/branch_name
delete local branch
git branch -D branch_name
reset working tree
git reset (commit hash or branch name)
reset working tree and discard all local changes
git reset (commit hash or branch name) --hard
stash all local changes
git stash
list stash
git stash list
applies last item on stash onto working tree
git stash pop
revert commit
git revert (commit hash)
cherry pick a commit
git cherry-pick (commit hash)