Skip to content

Instantly share code, notes, and snippets.

@jeanlescure
Last active January 24, 2019 17:24
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 jeanlescure/da39737d64051d4b242c787c3d5d3fa8 to your computer and use it in GitHub Desktop.
Save jeanlescure/da39737d64051d4b242c787c3d5d3fa8 to your computer and use it in GitHub Desktop.

Change wrong user name and email in all commits

Source: https://stackoverflow.com/a/4982271/2731075

git filter-branch --env-filter 'if [ "$GIT_AUTHOR_EMAIL" = "incorrect@email" ]; then
     GIT_AUTHOR_EMAIL=correct@email;
     GIT_AUTHOR_NAME="Correct Name";
     GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL;
     GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; fi' -- --all

Split git .pack files into smaller packs

Source: https://stackoverflow.com/q/46093437/2731075

git repack --max-pack-size=45m -a

When I get error trying to push git.backup:

GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.

Get all branches on a repo

Source: https://stackoverflow.com/a/10312587/2731075

git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all

Change .git directory name for single git command

Source: https://stackoverflow.com/a/795575/2731075

git --git-dir=git_directory status

Push single commit to remote when there are multiple local commits

Source: http://blog.dennisrobinson.name/push-only-one-commit-with-git/

git push <remote name> <commit hash>:<remote branch name>

Note: This will push all commits up to and including the specified commit

Rename a local and remote branch

1. Rename your local branch.

If you are on the branch you want to rename:

git branch -m new-name

If you are on a different branch:

git branch -m old-name new-name

2. Delete the old-name remote branch and push the new-name local branch.

git push origin :old-name new-name

3. Reset the upstream branch for the new-name local branch.

Switch to the branch and then:

git push origin -u new-name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment