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 pushing and pulling, and making the installed version of Git comparable with (the majority of) http://git-scm.com/book/en/ .
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:
- Must be distributed.
- Must be fast.
- 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.
emerge --ask dev-vcs/git
There are lots of really good tutorials on Git, so this article will not re-invent the wheel. Here are some I know and like, but any search engine will show you lots of examples.
- Official documentation
- Video tutorials
- Free, good basic first-time tutorial
- The first section is free, the rest are paid.
- A really straightforward tutorial
git config --global user.email "email@example.com"
git config --global user.name "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:
<maybe add some other files which will be included in the initial state of the project>
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:
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:
git add README.TXT
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: http://git-scm.com/book/en/Git-on-the-Server-Git-Daemon
If you're not sure, then skip this section.
Start by creating the needed group, user, and home directory.
The user uses the
git-shell to prevent normal shell access.
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.
... GIT_USER="git" GIT_GROUP="git" ...
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 First Commit
On the server:
git to make sure all objects are owned by this user
Create a bare repository:
git init --bare
On a the client station:
git add test
git config --global user.email "firstname.lastname@example.org"
git config --global user.name "dev"
git commit -m 'initial commit'
git remote add origin email@example.com:newproject.git
git push origin master
Clone a repository:
git clone firstname.lastname@example.org:newproject.git
Gui Repository Management
Git ships with a tk GUI. You can invoke it using this command:
user ~/repository.git $