mario::konrad
programming / C++ / sailing / nerd stuff
git
© 2010 / Mario Konrad

Alias

[alias]
    graph = log --graph --pretty=format:'%Cred%h%Creset-%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset %C(bold blue)`<%an>`%Creset' --abbrev-commit --date=relative
    daily = log --since '2 days ago' --oneline

Cheatsheet

Basic

Undo all local Modifications

$ git checkout -f

Checkin Modifications

$ git commit -a

Branches

List all Branches

$ git branch

Change current Branch

$ git branch $BRANCH

Obtain diff between current Branch and master Branch

$ git diff master..HEAD

Merge Branches into another

$ git checkout branch_m
$ git pull . branch_a
$ git pull . branch_b

Simple Local Server

Initialize ''bare'' repository:

$ git init --bare repository.git

Configure repository for push:

$ cd repository.git
$ git config daemon.receivepack true

Start server:

$ git daemon --verbose --export-all --base-path=/path/to/base /path/to/base

Workflow

# set up new project
cd project
git init
git add .
git commit -a -m "Initial commit"

# edit a file
vi file.php
git commit -a

# add a file
vi new.php
git add new.php
git commit -a

# see the log
git log

# make a branch
git branch working
git checkout working
# or in one step
git checkout -b working

# add some changes to this branch
vi file.php

# see what you changed
git status

# check it in
git commit -a

# see all branches
git branch

# go back to the first branch (initial branch is called "master" by default)
git checkout master

# make some other changes
vi other.php
git commit -a

# merge the working branch into this one
git merge working

# see the branches and merges in a graphical browser
gitk --all

# let's do a log of all commits in "working" that don't exist in "master"
git log master..working

# hmm let's undo that last merge (tip of branch is HEAD, one commit back is HEAD^.. we are "popping" one commit)
git reset --hard HEAD^

# push your changes out (push the tip of local "master" branch to remote "incoming" branch)
git push foo.bar.com:~/myrepo master:incoming

# pull changes from another repo (remote "feature1" into local "feature1" branch)
git pull baz.bar.com:~/otherrepo feature1

# move the branch point of the "working" branch to the top of the "master" branch
git checkout working
git rebase master