these are notes and tricks i've collected over the years when teaching people to use git for the first time or making them more productive. git is a pretty serious tool that can make your day-to-day process really smooth and simple if you know how to bend it in a few ways.
Open your ~/.gitconfig file and add the following
[github]
user = <your-github-username>
[user]
name = <your-full-name>
email = <your-email-address>
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
whitespace = red reverse
[color "status"]
added = yellow
changed = green
untracked = cyan
[core]
whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol
the settings above will give you a really nice start to using git effecitively. git is extremely customizable. you should definitely have a look of the config chapter in the git book.
this is your global configuration file and will make sure you have sane
defaults everywhere. i recommend setting your default's for name, username and
email to what you use when contributing to open source. for work repos,
i recommend setting your information to be your work email either by editing
the .git/config to be
[user]
name = <your more official work name>
email = <your work email address>
you can also just do that from the command line
cd <my project dir>;
git config <your more official work name>;
git config <your work email address>;
in general, if you see a docs that say to use git config --global for something,
just don't.
copy and paste the below into your shell
cd ~/;
git clone git://gist.github.com/114160.git .githelper;
echo "source ~/.githelper/gistfile1.sh" >> ~/.profile;
source ~/.profile;
this will make your life better. it adds several shortcuts to simplify the process as well as adding extra arguments to your commands to remove some of the most common gotchas. this script will also add the current repo and branch to your command line prompt.
freebase,f: fetch and rebase the current branch== git pull --rebasecommit,c: create a new commit of all changes files== git commit -apush,p: push local commits to the remote repository== git push origin <current_branch_name>status,s:== git statusnewbranch <name>: create a new branch from current== git pull --rebase && git checkout -t origin/<name>deletebranch <name>: delete a branch locallay. don't worry, it will prompt you before actually deleting== git branch -d <name>
- git-cola: Really powerful, Linux only
- SmartGit: Commercial, All Platforms
- qgit: QT based, All Platforms
- TortoiseGit Just like TortoiseSVN, Windows
- StupidGit Really strong submodule support, All Platforms
there are too many of these to list. meld is great for unix. Kkleidoscope for mac.
fto get any changes- got conflicts?
git rebase --abort && git pull;
- still have conflicts?
- resolve them in each file
- run
add <file-path>for each file that was in conflict cto commit the resolved conflict statepto push the changes to the remote
- no conflicts?
- you win.
- almost always the case when several people aren't making big changes to the same code
- got conflicts?
- do work
a <path>to add new filescto save state locallyfto make sure nothing has changed on the remote before we pushpto send your changes to the remote
git pull is git fetch and then git merge to apply the changes from the
remote. freebase is git fetch and then
git rebase remotes/origin/<branch-name>.
freebase will interleave your changes with any remote changes.
pull will use merge to combine your local changes and the remote changes.
it is highly preferable to use freebase over pull as it makes the history
much cleaner and easier to visualize, but you can always just use pull.
say we want to merge featureA branch into master:
checkout master;
f;
checkout featureA;
f;
git merge master;
# resolve any conflicts
p;
checkout master;
git merge featureA;
p;
@todo (lucas) add integrate <feature_branch> into <branch> alias
github has great documentation for dealing with merge conflicts but in general the workflow goes like this
- files in conflict will be shown by
statusin red and listed as both modified - resolve the conflicts in each file
add <file-path>for each file that was in conflictcto commit the resolved conflict statepto push the changes to the remote.
if you are used to using the synchronize view in eclipse a lot, here's a simple way to get the same info from the command line
git fetch && gitk --all &git fetch && gitx- SmartGit:
git fetchthenQuery -> Logfrom the file menu
- github flow walkthrough of github's process
- gitflow
- cheat git
- Zack Rusin
- Jan Krüger
- Windows 7 Gadget
there are millions of these. find the style that fits your workflow best. most are very good, except those that mention nothing about fetch and rebase.