Skip to content

Instantly share code, notes, and snippets.

@yifanz
Created September 2, 2012 06:30
Show Gist options
  • Save yifanz/3595355 to your computer and use it in GitHub Desktop.
Save yifanz/3595355 to your computer and use it in GitHub Desktop.
Notes on common git operations
# Undo last commit and put changes into staging
git reset --soft HEAD^
# Change the last commit
git commit --amend -m "Oops, forgot to add this to last commit"
# Totally undo the last commit
git reset --hard HEAD^
# Undo local changes to a file
git checkout -- index.html
# Add/remove a remote repository
git remote add somerepo https://github.com/somerepo.git
git remote rm somerepo
# show remote repositories
git remote -v
# Send local changes to remote repo, the -u makes this the default remote next time you can just run git push
git push -u somerepo master
# Diff the working copy with the index
git diff
# Diff the index with HEAD
git diff --cached
# Diff the working copy with HEAD
git diff HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment