How to setup git repository

11 steps you need to follow to setup a git repository privately as a non root user on linux. I am going to cover how to do this on a RedHat Enterprise Linux Server as this is a very common OS for companies needing service level agreements.

This guide assumes that git is already installed on the network, and that it is accessible from the user you are using on the machine you want to perform the setup on. Git will work over NFS, so you can follow this guide if your system using the network file system to access git.

In this guide, there will be one or more users working on local copies of the code, and there will be a remote user ( foouser ) on a target machine ( remote1 ) that will host the private repository that will be the remote.

Please follow these steps to setup git repository privately on an internal network.

Create SSH keys for each user that will be accessing this private git repository. Copy the public ssh keys of each user over to the users directory on the target machine and concatenate them onto the authorized keys file. If you are using c shell as the system default, make sure to add the location of the git binary to the PATH environment. You can do this by adding a setenv line to the .cshrc file of the user on the machine you are setting the git repository up on. Create a sub directory called git off of the home directory of the user hosting the remote repository on the target machine. Change into that directory and create your first project . Please note that the project directory under the git sub directory must end its directory name in .git. Lets pretend that I am setting up a project for a Perl module Prolog::Utility::FromPerl I would create a called Prolog-Utility-FromPerl.git with the following command git init –bare Prolog-Utility-FromPerl.git Now as one of your other users on their local machine create a directory where you will do all of your local development, I just use the same directory name git. Then under this directory create a directory for your Perl module project called Prolog-Utility-FromPerl without the .git ending Change into that directory cd ~/git/Prolog-Utility-FromPerl/ and run the following command. In this command, the name of the remote target machine that will host the remote git repository is called remote1 and the username with the remote git directory is called foouser. git init && git remote add origin foouser@remote1:/home/users/foouser/git/Prolog-Utility-FromPerl.git Now on your local machine create the first file under your local project directory ~/git/Prolog-Utility-FromPerl/ let’s assume you create a README.txt file with your favorite editor. After saving the file, run the following commands to commit the file to your local git repository git add README.txt Then git commit -m "initial commit of README" Now let’s push your local changes to the remote git repository you setup with the following command git push origin master Finally lets clone this new project with a different user that you setup in step 1 on a different local machine with the command git clone foouser@remote1:/home/users/foouser/git/Prolog-Utility-FromPerl.git

Typing out these really long paths can get a bit tedious, so I would recommend that you setup

some shortcut aliases in your git config file to make your use of git more productive. If you need some help doing this, please leave me a comment, and I can write a guide on the most useful git shortcuts and aliases to put in your .gitconfig file

To learn more about git, there is a great free online book for learning git called Pro Git that you can reference.