Skip to content

Instantly share code, notes, and snippets.

@anapaulagomes
Last active April 29, 2019 13:31
Show Gist options
  • Save anapaulagomes/9344332ad01d3a2755080c13b05bdd66 to your computer and use it in GitHub Desktop.
Save anapaulagomes/9344332ad01d3a2755080c13b05bdd66 to your computer and use it in GitHub Desktop.
Git tricks

Git Tricks

Add changes by chunks

git add -p

Squash, edit, delete etc (interactive rebase)

git rebase -i HEAD~5 # last five commits

Rename a branch

git branch -m <oldname> <newname>

Delete untracked files

git clean -n # visualize files to be deleted

git clean -f # delete the files

Delete a branch

git branch -d fix-bla

git branch -D fix-bla # force

Remove after add to .gitignore

git rm -r --cached

Order branchs by commit date

git for-each-ref --sort=-committerdate refs/heads/

Nice references:

15 Git Commands You May Not Know

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