From Gentoo Wiki
Jump to: navigation, search

External resources

git distributed revision control and source code management. The goal of this article is to easily get a git repository up and running pushing and pulling, and making the installed version of git comparable with (the majority of) .

Git was developed by Linus Torvalds for use on the Linux Kernel, and other Open Source projects. According to a talk he gave for Google, he was searching for an SCM and used three criteria which brought the number of adequate systems to zero:

  1. Must be distributed.
  2. Must be fast.
  3. What you get out MUST BE EXACTLY what you put in, or you get an error.

Since there were no satisfactory options, he wrote Git.


Install dev-vcs/git:

root # emerge --ask dev-vcs/git


There are lots of really good tutorials on git. Let's not re-invent the wheel. Here are some I know and like, but any search engine will show you lots of examples.

    1. Official documentation
    2. Video tutorials
    1. Free, good basic first-time tutorial
    1. The first section is free, the rest are paid.
    2. A really straightforward tutorial


user $ git config --global ""
user $
git config --global "your_username"


If you're the only one using your project, or if you're creating something which will be shared in a distributed way, then you should start on your workstation. If you intend to have a central server which everyone uses as the "official" server (e.g. github) then it might be easier to create an empty repository there.

This section, describes creating the repository on your workstation.

Here's an example of creating a project on your workstation:

user $ cd ~/src
user $
mkdir hello
user $
cd hello
user $
user $
<maybe add some other files which will be included in the initial state of the project>
user $
git init

You're done. You've created a local repository. It's in the .git folder, so don't delete your hello folder unless you mean to lose everything.

Your repository is the .git folder inside the main hello folder. If you delete ~/src/hello, then your repo is gone.

Now, let's say we make some edits:

user $ cat "Hello, world!" >> README.TXT

Git needs you to specify that we want to keep the changes we just made, so we need to add it before we commit:

user $ git add README.TXT
user $
git commit -m "Added text to README.TXT"

Look to the tutorials to go further.


In this section will cover setting up a git server for remote project management through SSH.

Note: The git server is only necessary if you intend to have an unauthenticated read-only server for people to get your code from. See here:

If you're not sure, then skip this section.

Initial Setup

Start by creating the needed group, user, and home directory. The user uses the git-shell to prevent normal shell access.

root # groupadd git
root #
useradd -m -g git -d /var/git -s /usr/bin/git-shell git

Edit /etc/conf.d/git-daemon to change user from "nobody" to "git" and start the daemon.


root # /etc/init.d/git-daemon start

SSH Keys

SSH is the prefered method to handle the secure communications between client and server. For Git to work properly, you must have private/public key logins enabled and all client public keys added to /var/git/.ssh/authorized_keys. For more information and instructions on how to enable, create, and share keys, please see the SSH - Passwordless Authentication wiki page.

this step must be completed before continuing


Create a Repository and make the First Commit

On the server:

Become user git to make sure all objects are owned by this user

root # su git

Create a bare repository

user $ cd /var/git
user $
mkdir /var/git/newproject.git
user $
cd /var/git/newproject.git
user $
git init --bare

On a the client station:

user $ mkdir ~/newproject
user $
cd ~/newproject
user $
git init
user $
touch test
user $
git add test
user $
git config --global ""
user $
git config --global "dev"
user $
git commit -m 'initial commit'
user $
git remote add origin
user $
git push origin master

Common Commands

Clone a repository:

user $ git clone

Gui Repository Management

Git ships with a tk gui.

user ~/repository.git $ gitk

See Also

External resources