Git local repo to remote server

posted on: 2011-08-02 11:37:56




You already have a local git repo and want to push to a new remote repo?

Since I have recently switched from using SVN to Git for version control I thought that I would post a helpful tutorial for people who have a local Git repo on their machine and want to push this to a remote server.

Coming from using SVN I am more familiar with having a remote repository on a server and checking out and committing back to it. However recently while using XCode on Mac OS X while creating a new project I was asked if I wanted to create a local Git repository... So I checked the checkbox and now have a local Git repo, great. But now I want to clone this to my server so I can ensure I have a back up of my local repo on my server. and this is how I did it.

On your server.

# mkdir /var/git
# cd /var/git
# mkdir yourprojectname
# cd yourprojectname
# git init-db


On your local machine on your project folder

# git remote add origin ssh_user_name@yourserver.com:/var/git/yourprojectname
# git push --force --all origin

From then on all you will need to do after your first push is.

# git push