Setting up a git repository

Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

First of all we need to install git on the remote server (lets call it server.com). The easiest way is to use yum to download and install the git software. The command is yum install git. yum will download all necessary files including dependencies if needed and … install the base git software.


OK now that the software has been installed in the server .. its time to create a Git repository for your project in server.com.

Login to remote server
$ ssh server.com
Last login: …..

Create a directory (in any location you like) for the repository. I will be using /usr2/git/ as the remote dir here

$ mkdir /usr2/git/project.git

Now go to the newly created directory and Create your new project git repo as a bare Git repository using the following command

$ git –bare init
Initialized empty Git repository in /usr2/git/project.git

Now that the repo has been created in the server, lets focus on your local machine. I will be starting with a new directory on the local machine. So create a dir in the local machine and go in to the dir

$ mkdir project
$ cd project

Now Initialize the local repository

$ git init
Initialized empty Git repository

Now we have our repository in the server (remote branch) as well as the one in our local machine (local branch), lets add it to our local repository as a remote server called “origin” using git remote add,

$ git remote add origin ssh://[email protected]/usr2/git/project.git

Next step is to upload the code base code to the remote server. Before doing this, copy your code to the local branch. Once this is done prep the files for upload using the following command

$ git add .

git add will add files to the “index”. The index represents “your current changeset” and is what will be committed to the remote branch. Unlike Subversion modified files won’t be committed unless you git add them first. Now Now let’s commit this code whilst adding a comment mentioning the reason for commit.

$ git commit -m “Initial Code Upload to remote repo”

Now The time has come to push our local master branch to the origin’s master branch. We do that using the git push command

$ git push origin master

That’s it .. we are done. If you need to do more pushes, then it can be done by repeating the git push command.

If you need to pull an update from the remote branch, use the following command

$ git pull ssh://[email protected]/usr2/git/project.git


3 comments to Setting up a git repository

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  


*

This site uses Akismet to reduce spam. Learn how your comment data is processed.