Skip to content

Instantly share code, notes, and snippets.

@oscarotero
Last active December 3, 2016 11:29
Show Gist options
  • Save oscarotero/7749998 to your computer and use it in GitHub Desktop.
Save oscarotero/7749998 to your computer and use it in GitHub Desktop.
# Undo latest commit
git reset --soft HEAD^
# Undo the changes of a commit (creating a new commit)
git revert <commit>
# Undo latest merge (before push)
git reset --merge ORIG_HEAD
# Merge a branch using the version of the current branch in case of conflicts
git merge <branch> -s ours
# Discard changes for a particular file after commit
git reset HEAD <file>
# Unstage the current staged changes
git reset
# Create, fetch a remote branch and switch to it
git checkout --track <remote>/<branch>
# Remove a file from git but not from disc
git rm --cached <file>
# Reapply an old commit again
git cherry-pick <commit>
# Ignore the changes of a file
git update-index --assume-unchanged <file>
# Not ignore the changes of a file
git update-index --no-assume-unchanged <file>
# List all "assume-unchanged" files
git ls-files -v|grep '^h'
# Display who did the latest change in each line (ignoring whitespaces)
git blame <filename> -w
# Remove all local branches removed in remote
git fetch origin --prune
# Remove untracked local files
git clean -f
# Remove untracked local files and folders
git clean -fd
# Remove remote branch
git push <remote> --delete <branch>
# Go to an old commit
git read-tree <commit>
# Use the ~/.gitignore file to ignore globally certain files
git config --global core.excludesfile '~/.gitignore'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment