# Git tips
Take a look at the Git cheat sheet.
Resources:
- genomewiki
- Git scm
- Justin Hileman
- Daniel Kummer
- Git Cheatsheet
- Resources for learning Git
- Git tips from the pros
# Solving merge conflicts
When merging with Git, conflicts can happen. To resolve them, simply:
- find the conflicted files with
git status
(they'll have theunmerged
mention) - edit the conflicted files and make the necessary modifications
git add
the resolved filesgit commit
to finish the merge
# Managing ref updates (checkout, reset, commit, merge, etc)
- checking the history of ref updates:
git reflog [show <branch>]
- undoing last ref update:
git reset HEAD@{1}
Source: Stack overflow: Undoing git reset
# Splitting a commit
- select the commits:
git rebase -i HEAD~<number>
- mark the commit: change
pick
toedit
- save and quit the editor
- undo the commit:
git reset HEAD^
- stage and commit:
git add <file>; git commit -m <message>
- apply the split:
git rebase --continue
Source: Git scm: Splitting a commit
# Join last commits into the previous one
- select the commits:
git rebase -i HEAD~<number>
- mark the commits: change
pick
tofixup
Source: Git scm: Squashing commits
# Reorder commits
- select the commits:
git rebase -i HEAD~<number>
- change the order of the lines
Source: Git scm: Reordering commits
# Modify commit
⚠️ These tips work for un-propagated commits
# Change the last commit message
git commit --amend
# Modify specific commit
- start rebase:
git rebase -i <number>^
- mark the commit: change
pick
toedit
- edit your files
- add them
git add <filepattern>
git commit --amend
- And return to the head with
git rebase --continue
# Commit part of a file
- select the file:
git add -p <file>
- choose what to do:
- accept the chunk: hit
y
- reject the chunk: hit
n
- select part of the chunk: hit
e
, ors
if available
- accept the chunk: hit
- save and quit the editor
- commit:
git commit -m <message>
Source: Git scm: Staging patches
# Reset a local branch from remote branch
- start fetch:
git fetch <remote>
- reset from the chosen remote:
git reset --hard <remote>/<branch>
- check you have no differences between the two branches:
git diff <branch>...<remote>/<branch>
should respond nothing.
Source: Git scm: Reset history
# Keep a fork updated
# Track the repository
- git clone git@github.com:johndoe/knowledge.git
- cd knowledge
- git remote add upstream git@github.com:gnugat/knowledge.git
# Update the repository
- git fetch upstream
- git rebase upstream/master