Skip to content

Instantly share code, notes, and snippets.

@redmanmale
Created February 27, 2017 16:26
Show Gist options
  • Save redmanmale/a0ab4fda0329950ce25e3469890cbb9c to your computer and use it in GitHub Desktop.
Save redmanmale/a0ab4fda0329950ce25e3469890cbb9c to your computer and use it in GitHub Desktop.
personal git tips&tricks
Remove all deleted files from git stage:
git rm $(git ls-files --deleted)
Update all subrepos in folder
find . -maxdepth 1 -type d -exec sh -c '(cd {} && git pull)' ';'
find . -maxdepth 1 -type d -exec sh -c '(cd {} && git checkout develop && git pull)' ';'
Clean remote and local git:
1. git remote prune --dry-run origin //-dry-run shows remore branched to be deleted without deleting
2. Delete all local branches that was merged by pattern
git branch --merged | grep "feature/" | xargs -n 1 git branch -d
//-v after grep is inverting
force merge with only external changes (e.g. merge new dev into old master):
git merge -X theirs develop
git tag tag-name
git push origin tag-name
git merge --no-ff --no-commit
git commit --author="name <email>"
force pull:
git fetch --all
git reset --hard origin/master
clean all (include bin/debug)
git clean -xdf --dry-run
clean all (include bin/debug) except file -e
git clean -x -d -f -e /**/*.user
change author for entire repo (whole history):
git filter-branch --env-filter '
OLD_EMAIL="old-email"
CORRECT_NAME="new-name"
CORRECT_EMAIL="new-email"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
remove file from entire repo (whole history):
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch ./appsettings.json' --prune-empty --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment