2010-05-10

GIT

git config --list
git config --global user.name "dupa jas"
git config --global user.email fdsf@das.pl
git config --global core.editor vim
git config --global merge.tool diff
git help command
man git-command
git status
git init         #create git structure in .git directory

base commands:

git add . #add all files inside current directory to track git rm file #remove file git mv file1 file2 #move file git commit -a m "comment" #commit all without staged git commit -v #show changes to commit git commit --amend

branching:

git branch -a #list all branches, present with flag * git branch [branch_name] #create new branch git checkout [branch_name] #move to branch git checkout -b [branch_name] #create and move to new branch git checkout -- [file] git branch [branch_name] [hash|tag] #new branch branch_name from hash or tag git branch -d [branch_name] #remove branch git branch --merged git branch --no-merged

logging:

git log git log -1 #show last one commit git log -p -2 #show diff of two last commits git log --pretty=oneline|short|medium|full|fuller|email git log --pretty=format:"%h - %an, %ar : %s" git log --pretty=format:"%h %s" --graph git log --merged #only merged commits

diffs:

git diff #differences between tracking (working directory) and staged files git diff --staged #differences between staged and last commit git diff --cached #as above?

tagging:

git tag #show tags git tag -a v1 -m 'comment' #add new tag git show v1 git tag -a v1.1 hash #tag old commits

other:

git merge [branch_name] #ex inside master branch merging changes from branch branch_name git ls-files --stage #show files with hash in stage git hash-object [file] #make SHA1 hash for file git mergetool #choose merge tool .gitignore #file with list of ignoring files info/exclude #as above but for whole project

initialize git project on server without working directory:

mkdir project-01.git cd project-01.git git --bare init

initialize git project in local directory:

git init git add . git commit -m "initialize project"

initialize bare git project from current project;

- developer1: git clone --bare [current_project] [bare_project].git git remote add [alias] [path_to_bare_project] git remote set-head [alias] master - developer2: git clone [user]@[developer1_hostname]:[path_to_developer1_bare_project]

send to remote server

git remote add [alias] [user]@[server]:/[path on server to git project dir] #add remote alias git push origin master #push from master branch to origin alias git remote -v #check remote server git remote add [alias] user@server:path/project.git #add remote repo git remote show origin git remote rename file1 file2 git remote rm file git clone [url] #clonning repo, not checkout, with all history files etc. git clone git://url dir_name #clone with make local directory dir_name,track master on remote git clone http(s):// git clone user@server:/path #ssh clone with default alias origin creation etc. git clone --bare [project_path] [bare_project_path].git #create bare (without working dir) project from project with working dir git fetch [alias] #fetch data from remote server with alias to local branch (create pointer only), till last fetch or clone, git diff [alias] #compare differences git merge [alias] #merge differences git pull [alias] [local_branch] #as above 3 steps in 1 git remote -v #get remote alias git push [remote_alias] [branch_name] #send branch branch_name to remote repo git push [remote_alias] [branch_name]:[remote_branch_name] #as above with name change git push [remote_alias] :[branchname] #remove remote branch 

working dir-------staging area--------git dir

.git/objects #all content .git/refs #branches .git/HEAD #currently checked out .git/index #staging area (index)