Skip to content

Instantly share code, notes, and snippets.

@jennings
Last active September 27, 2015 15:47
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 jennings/1293458 to your computer and use it in GitHub Desktop.
Save jennings/1293458 to your computer and use it in GitHub Desktop.
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
# https://github.com/anurse/git-credential-winstore
# 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