Workflow for gitorious and github
When needing to merge upstream changes back into master:
Delete remote branch
git push origin :name-of-remote-branch # OR git push origin --delete name-of-remote-branch
Amend the previous commit that has not been propogated (i.e. undo it, then start a new one with the pending changes in the index):
git commit --amend -a -m "New commit message"
Undo a commit that has not been propagated:
git reset --soft HEAD^
just changes the repository without changing the files you've edited on disk. However:
git reset --hard HEAD^
will reset both repository and revert files.
Once a commit that has been propagated, there is no way to undo. However, the following will create a new commit undoing the previous commit's changes:
git revert HEAD
Pull with rebase instead of merge
git pull --rebase
Configure a branch to always do a rebase instead of a merge:
git config branch.$BRANCH_NAME.rebase true
Remove files from the repository that should have been ignored by .gitignore:
git rm -r --cached . git add . git status git commit -m ".gitignore is now working"
Ignore whitespace bullshit
# Ignore white space when pulling or merging git pull -Xignore-space-change git merge -Xignore-space-change # Ignore white space changes when diff'ing git diff --ignore-space-change
Rebase a branch
# Without having branch-you-want-to-rebase checked out git rebase branch-you-want-to-rebase branch-to-rebase-from # With having branch-you-want-to-rebase checked out git checkout branch-you-want-to-rebase git rebase branch-to-rebase-from
Rebase off a branch that itself had been rebased (keep the un-rebased branch around as old-branch-to-rebase-from):
git rebase --onto branch-to-rebase-from old-branch-to-rebase-from branch-you-want-to-rebase
If you want to rebase but get updated stamps (do this independently of reordering/merging commits with git rebase -i:
git rebase --ignore-date
Per-repository user settings
git config user.name 'Samat K Jain' git config user.email 'email@example.com'
# Remove untracked files and directories, dry run. `-n` for dry run. git clean -df -n
The Git Parable: Describes building a system like git, from the ground-up
CIA's git tips & tricks sheet is interesting, and oddly similar to this one.