Skip to content

Instantly share code, notes, and snippets.

@Nimrodda
Last active September 5, 2017 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nimrodda/eca2e0b316b82a343467 to your computer and use it in GitHub Desktop.
Save Nimrodda/eca2e0b316b82a343467 to your computer and use it in GitHub Desktop.
Git Tricks

Delete tracked files in directory: git ls-files -z | xargs -0 rm -rf

Delete a file from history of a branch: git filter-branch --index-filter "git rm --cached -f --ignore-unmatch <path/filename>"

See log with files changed: git log --name-status

Delete remote branch: git push origin :<remote-branch-name>

Split repository (make a subfolder a new repository):

  1. clone the branch with git checkout -b <new-branch-name>
  2. turn the newly cloned branch to be its own repository: git filter-branch --prune-empty --subdirectory-filter <subdir>
  3. the cloned branch will now have only commits related to the files under and we can push it to a new repository git push <remote> <branch>' (before that we need to have the remotedefined withgit remote ...`

See the git commands done so far: git reflog

Undo any git filter-branch command:

  1. get the ref ID from git reflog
  2. git reset --hard HEAD@{ID}

Search for commit hash by message: git log --all --grep='message'

Get closest tag that contains commit hash git describe --abbrev=0 --tags

Delete obsolete remote branches: git remote prune origin

Show all tags that contain specific commit hash: git tag --contains <commit hash>

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