Sunday, July 18, 2010

Git a nutshell

I read
http://progit.org/

I use
http://nbgit.org/

Install


Package name
$ yum install git-core
$ apt-get install git-core

Global setting
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

Local


Creating Repository
  1. init
  2. clone
a)
//go to project folder:
$ git init

b)
$ git clone git://github.com/schacon/grit.git myDestinationFolderName

Ignore files
//cat .gitignore
doc/*.txt
*.log

Add files
$ git add [file name, folder name, or wildcard]
$ git add submodule1/PrimaryClass.java
$ git add .
$ git add *.java

Committing
$ git commit –m ”your commit message”

Status
$ git status

What's changed
$ git diff

Remove
$ git rm log/\*.log

Show history
$ git log

Show tags
$ git tag

Tags
  1. annotated
  2. lightweight
a)
Add tag
$ git tag -a v1.4 -m 'my version 1.4'

Show tag
$ git show v1.4

b)
Add tag
$ git tag v1.4-lw

Remote


Show remote repositories
$ git remote -v

Add new remote repository
$ git remote add pb git://github.com/paulboone/ticgit.git

Fetch
To retrieve remote changes without merging
$ git fetch [name of remote repository]

Pull
Pulling is the combination of a fetch and a merge.
$ git pull
$ git pull [remote name]
$ git pull [remote name] [branch name]

Send your work to remote repository
$ git push origin master

Search remote repository
$ git remote show origin

Rename remote repository
$ git remote rename pb paul

Remove remote reposirory
$ git remote rm paul

Send tag to remote repository
$ git push origin v1.5
or
$ git push origin --tags

Branching


Show branches
$ git branch -a

Create new branch
$ git branch [new branch name] [from branch]
$ git branch [new branch name]

Choosing a Branch
$ git checkout [branch name]

Merging
$ git checkout master
$ git merge hotfix

Delete branch
$ git branch -d hotfix

Send local branch "serverfix" to remote branch "awesomebranch"
$ git push origin serverfix:awesomebranch

No comments:

Post a Comment