Jump to content

Git

From HW wiki

Git homepage - look there for manuals, tutorials and other interesting things or read on bellow.

Install Git

  • In Debian (Ubuntu):
    apt-get install git-core
  • Git for Windows (MSys) - works quite well. There are other possibilities such as git for Cygwin.
  • FreeBSD:
    cd /usr/ports/devel/git/ && make install clean
  • NetBSD:
    cd /usr/pkgsrc/devel/scmgit && make install clean

Correct Git version

For submodule support (used by sysless framework) you need at least version 1.5.3.4. Check your version by

git --version

Links for newer version for various distributions:

Graphical Frontends

  • qgit
  • git gui
  • gitk
  • tig

Basic commands

  • Initialize a brand new Git repository
$ cd /home/project
$ git init         # with git older than v1.5, use init-db instead of init
$ git add .
$ git commit
  • First checkout
$ git clone /home/project
$ git clone username@someserver.org:/path/to/repo.git
  • MinGW port check out project
git clone ssh://username@someserver.org/path/to/repo.git
  • Browse repository and history using a graphical interface
$ qgit

To be able to do commits from QGIT, check View->Check working dir

  • Usefull commands
$ git log
$ git log --stat --color
$ git <whatever> --help
$ man git-<whatever>
  • Before commit
$ git status
$ git diff [--color]
$ git add <file>
$ git commit [-m "message"]
  • To commit all modified files without the need of
    git add
$ git commit -a [-m "message"]
  • Send your commits to the central repository
$ git push
  • Update from server
$ git pull
  • Pull from others
$ git pull name@1.2.3.4:/path/to/repo.git

Configuration

  • Global configureation
$ git config --global user.name "Your Name Comes Here"
$ git config --global user.email you@yourdomain.example.com
$ git config --global color.diff auto
$ git config --global color.status auto
$ git config --global color.status auto
  • You can change it for individual repositories either without --global or in
    .git/config</tt>:
[user]
       name = "Your Name"
       email = "username@example.com"
[color]
       diff = auto
       status = auto
       branch = auto

== Advanced commands ==

  • Add, move or remove any files
* git add file
* git mv file
* git rm file
  • Shows the commits which add or remove any file data matching ''string''
$ git log -Sstring
  • Show what revision and author last modified each line of a file
$ git blame file
  • Display changes since the last git-update-index:
$ git diff
  • Display changes since the last commit:
$ git diff HEAD
  • List all changesets belonging to a specific file
$ git-whatchanged file
  • Delete all untracked files
$ git clean
  • Restore a file from the last revision
$ git checkout /file/you/want/to/restore
  • Force to restore all modified files
$ git checkout -f

== Branches ==

  • List all branches
$ git branch
  • Checkout a desired branch
$ git checkout name_of_branch
  • Create a new branch and make it current
$ git checkout -b new_branch master
  • Merge changes from one branch into another. Let us suppose that you do work on branch A and branch B,

and after work on those two branches is complete, you merge the work into mainline branch M.

$ git checkout M	# switch to branch M
$ git pull . A		# merge A into M
$ git pull . B		# merge B into M
  • Delete a branch
$ git branch -d branch_name
  • Switch to a commit 76ff365f7799e43883d214d7f66a48c5c595c7d2 from the master branch
$ git log

<pre>

commit 228ffa28d6b63c3baa809b5b6edf3b5e28336dc2
Author: Username <username@example.com>
Date:   Mon Dec 31 09:29:19 2007 +0100
   binary
commit 76ff365f7799e43883d214d7f66a48c5c595c7d2
Author: Username <username@example.com>
Date:   Mon Dec 31 09:21:14 2007 +0100
   Initial commit of the Helloworld.
$ git branch test1 76ff365f7799e43883d214d7f66a48c5c595c7d2
$ git branch
 * master
 test1
$ git checkout test1
$ git branch
  master
 * test1
$ git log
 commit 76ff365f7799e43883d214d7f66a48c5c595c7d2
 Author: Username <username@example.com>
 Date:   Mon Dec 31 09:21:14 2007 +0100

    Initial commit of the Helloworld.
  • Switch back to the master branch and delete the test1 branch
$ git checkout master
$ git branch -d test1

Setting up a new project and a new remote git repository

  • On the remote host
$ mkdir /var/git/project
$ cd /var/git/project
$ git --bare init
  • On your box
$ mkdir /home/project
$ cd /home/project
$ git init                  # with git older than v1.5, use init-db instead of init
$ git add .
$ git commit -a
  • Put the following lines to your /home/project/.git/config
[remote "origin"]
       url = username@example.com:/var/git/project
       fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
       remote = origin
       merge = refs/heads/master
  • Push your project onto the host
$ cd /home/project
$ git push origin master
  • Test if your project has been pushed to the remote host correctly
$ cd /tmp
$ git clone username@example.com:/var/git/project
  • For more details follow the tutorial
http://toolmantim.com/article/2007/12/5/setting_up_a_new_remote_git_repository

Installation of the web interface

Other docs