Skip to content

Instantly share code, notes, and snippets.



Last active Sep 27, 2015
What would you like to do?
Miscellaneous Git commands

Rebase the changes branch-base..branch-head onto the master branch

git rebase --onto master branch-base branch-head

Cherry-pick the changes in B since it diverged from A onto the current branch

git checkout base-branch
git cherry-pick A..B

Create a new branch with no parent

# Old and busted
git symbolic-ref HEAD refs/heads/branch-name
rm .git/index
git clean -fdx

# New hotness
git checkout --orphan i-am-lonely

Credential helpers:

# OS X
git config --global credential.helper osxkeychain

# Windows
# Just run it, it installed itself into %APPDATA%
# (But make sure you unblock the file first)

Open the origin URL in the browser (I sure hope it's HTTP...)

# OS X
git config --global --replace-all alias.home "\!open \"\$(git config remote.origin.url)\""

# Windows
# If you can get this incantation right without PowerShell, I'd love to see it
git config --global --replace-all alias.home "!powershell.exe -Command 'start $(git config remote.origin.url)'"

Fix the damn MAX_PATH 260 character limit on Windows

git config --global core.longpaths true

Some handy aliases

git config --global alias.lg "log --oneline --graph --decorate"
git config --global alias.ignored "ls-files -ci --exclude-standard"

# git assume $FILE    -- never show the file as modified by "git status", "git add -A" and the like
# git unassume $FILE  -- return the assumed file back to normal
# git assumed         -- displays all files that are assumed unchanged

git config --global alias.assume "update-index --assume-unchanged"
git config --global alias.unassume "update-index --no-assume-unchanged"
git config --global alias.assumed "!git ls-files -v | grep '^h'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.