Introduction
This is a simple guide on how to create an empty git repository for development purposes, as well as creating a remote repository to push/pull to and from.
I am assuming you have a remote server, with SSH usersname and keys created for this guide. I find that using SVN is a good way to get going and hosting remote git repositories, and this is the way I previously used SVN for source code management.
Files already on local machine
If you have files already on a local machine the following code will turn this into a local repository:
$ git init
It’s as simple as that. Then use git add
and git commit
to commit the files to the master branch.
Creating the remote git repository
It’s all well and good to have a local git repository, but next we need to have somewhere central to manage this. I use SSH to talk to the remote git server. To create a remote SSH into that box, and by default I store my git repositories in /var/git/
. So firstly create a new folder for the repository, and then initiate a ‘bare’ repository.
$ mkdir /var/git/repo_name/ $ cd /var/git/repo_name/ $ git init --bare
That will create an empty repository in that location. We can now add the remote repository to the local branch, and push the contents to it, and test a checkout/clone elsewhere. So on the local box in the repository folder, carry out the following commands to add a remote, and push the new branch to it:
$ git remote add origin gunja@worker1:/var/git/repo_name $ git remote origin $ git push origin --all
That will push all the local bits to the remote server. To check that it worked, you just now need to move to a new folder, and try and clone it:
$ git clone gunja@worker1:/var/git/repo_name
References
http://git-scm.com/book/en/v2/






