From LQWiki
Jump to: navigation, search

Git is a revision control system that allows you to download and manage different versions of a program's source code.

Obtaining Git

Install git by means of your distribution as described at installing software. Or download it from

using git

Example: The Linux kernel

To obtain the linux kernel (+/-150MB) for example,

git clone git://;

A subdirectory will be created for your project to contain the source files. To upgrade your project later 'cd' to this created directory and type:

git pull origin;

Editing code

You can change your code using your favorite editor, To see the changes:

git diff

To undo changes, type:

git checkout -f

You can also create branches to make distinct changes. To list the branches, type:

git branch

The 'master' branch is the root of the source. To create a new branch for your own modifications, type:

git checkout -b BRANCH_NAME master

To change the current branch to another, type:

git checkout BRANCH_NAME

create a git server

git is technically not a server because it does not listen on a port, but is used over a command invoked via ssh. So, here is how you set up a git repository:

tweedleburg:~ # mkdir gittest
tweedleburg:~ # cd gittest/
tweedleburg:~/gittest # git init
Initialized empty Git repository in /root/gittest/.git/
tweedleburg:~/gittest # echo hello>world
tweedleburg:~/gittest # git add world
tweedleburg:~/gittest # git commit -am "first commit"
[master (root-commit) 4a0c108] first commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 world

Now you can clone your repository into another directory using

git clone ssh://root@localhost/root/gittest

See also

External links