From Gentoo Wiki
Jump to: navigation, search

External resources

Git is distributed revision control and source code management software. The goal of this article is to easily get a Git repository up and running.

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 a Source Control Management (SCM) and used three criteria.

SCM must:

  1. Be distributed;
  2. Be fast;
  3. Output exactly what was put in, or an error should be printed.

Since there were no satisfactory options Linus wrote Git.


USE flags

Optional USE flags for dev-vcs/git:
USE flag (what is that?) Default Recommended Description
blksha1 No Use the new optimized SHA1 implementation
cgi No Install gitweb too
curl No Support fetching and pushing (requires webdav too) over http:// and https:// protocols
cvs No Enable CVS (Concurrent Versions System) integration
doc No Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
emacs No Add support for GNU Emacs
gnome-keyring No Enable support for storing passwords via gnome-keyring
gpg No Pull in gnupg for signing -- without gnupg, attempts at signing will fail at runtime!
gtk No Include the gitview contrib tool
highlight No GitWeb support for app-text/highlight
iconv No Enable support for the iconv character set conversion library
mediawiki No Support pulling and pushing from MediaWiki
nls No Add Native Language Support (using gettext - GNU locale utilities)
pcre No Add support for Perl Compatible Regular Expressions
perl No Add optional support/bindings for the Perl language
python No Add optional support/bindings for the Python language
python_targets_python2_7 No Build with Python 2.7
subversion No Include git-svn for dev-vcs/subversion support
threads No Add threads support for various packages. Usually pthreads
tk Yes Add support for Tk GUI toolkit
webdav No Adds support for push'ing to HTTP/HTTPS repositories via DAV
xinetd No Add support for the xinetd super-server


Install dev-vcs/git:

root #emerge --ask dev-vcs/git


Before contributing to a project it is imperative to establish a user name and email for each user. Substitute the bracketed Larry references (brackets and everything in-between, but leave the quotes) in the next example for a personal user name and e-mail address:

user $git config --global "<>"
user $git config --global "<larry_the_cow>"


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.

The next list of commands will describe how to create a repository on a workstation:

user $cd ~/src
user $mkdir hello
user $cd hello
user $touch README.TXT
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

The new readme.txt file must be added (staged) before it can be included in the git repository. Use the next commands to stage the file and to make the commit:

user $git add readme.txt
user $git commit -m "Added text to readme.txt"


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

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

If 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.

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

SSH Keys

SSH is the preferred 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 initial 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 "larry_the_cow"
user $git commit -m 'initial commit'
user $git remote add origin
user $git push origin master

Common Commands

Clone a repository:

user $git clone

Repository management via GUI

Git ships with a tk GUI. Invoke it using:

user ~/repository.git $gitk

See also

External resources