Skip to content

Instantly share code, notes, and snippets.

@Bekt
Last active August 29, 2015 14:02
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bekt/5f36224899bb951f39aa to your computer and use it in GitHub Desktop.
Save Bekt/5f36224899bb951f39aa to your computer and use it in GitHub Desktop.
Git 101
# 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
@wuzzzzaah
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment