Creating A Git Repository

About Git:
git is a source-code management system (also known as a "revision control system"). It's similar to other systems like subversion, CVS, mercurial and bitkeeper. Since its introduction in 2005 git has become widely adopted because of its speed, simplicity, and its ability to allow widely distributed users to collaborate.

For more about git, see:
http://git-scm.com/
and http://en.wikipedia.org/wiki/Git_(software)

Setting up a Git Repository:

Git stores copies of your source code and revisions in a repository which is just a specially-configured directory. You can create your own git repository by creating a new directory (let's call it "/home/mst3k/myrepo.git" for this example) and using the git command to initialize it. For example:

mkdir /home/mst3k/myrepo.git
cd /home/mst3k/myrepo.git
git --bare init
If you look at the directory now, you'll see that several new files and subdirectories have been created:

ls -al /home/mst3k/myrepo.git

drwxrwxr-x   2 mst3k mst3k   4096 Feb 11 09:42 branches
-rw-rw-r--   1 mst3k mst3k     66 Feb 11 09:42 config
-rw-rw-r--   1 mst3k mst3k     73 Feb 11 09:42 description
-rw-rw-r--   1 mst3k mst3k     23 Feb 11 09:42 HEAD
drwxrwxr-x   2 mst3k mst3k   4096 Feb 11 09:42 hooks
drwxrwxr-x   2 mst3k mst3k   4096 Feb 11 09:42 info
drwxrwxr-x   4 mst3k mst3k   4096 Feb 11 09:42 objects
drwxrwxr-x   4 mst3k mst3k   4096 Feb 11 09:42 refs
That all there is to it! You're now ready to use your new repository.

Using Your Repository:

If you already have a project that you'd like to "check in" to your repository, go to the directory where your project lives. For this example, let's assume that you have some programs or some latex documents that you'd like to check into the repository, and that you've been working on them in the directory /home/mst3k/importantproject. Here's how you might proceed:

  • Go to the directory where you currently keep your copy of the source code:

            cd /home/mst3k/importantproject
    

  • Type the following:

            git init
            git add . #(note the dot)
    	git commit -m "Initial version"
            git remote add origin /home/mst3k/myrepo.git
            git push origin master
    

    That will put a copy of your code into the repository.

  • Another person can clone the repository by typing (logged in as him- or herself):

            git clone /home/mst3k/myrepo.git
    

    (This assumes that the other user has permission to read the directory /home/mst3k/myrepo.git.)

    This will give them their own local copy of the files to work on

    Note that users on remote computers can clone your repository using the ssh protocol, by subtituting a command like the following in place of the one above:

            git clone ssh://me@some.server.edu/home/mst3k/myrepo.git
    

    where "me@some.server.edu" indicates the user's name and the hostname of the computer on which your repository resides.

  • From then on, you can work as you normally would with your copy of the code. When you want to push your latest changes into the repository, type:

            git commit -a
            git push
    

  • The other person can then fetch and merge your changes by going into his copy of the project directory and typing:

            git pull /home/mst3k/myrepo.git
    

    (or using "ssh://..." as above, for remote users.)

Browsing Git Graphically:

You can use the command gitk to browse your git repository graphically.

More Information:

Here's more documentation and a tutorial document with much more about git:

http://git-scm.com/doc
and
https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-init