It’s actually quite easy to create a new remote GIT repository from a local repository in GIT 1.7. Many times you start a new small project and want to play around and somewhere on the line you start to think – “Hey this would be nice to work from different computers” or -“This is now critical software for my club, I need to share the code and secure it!” but you have it in a local repo.
0. If you don’t have a local repository you can start with creating one:
<you are standing in you project folder>
git init
git add *
git commit -m "My initial commit message"
1. Go to your server and create a new bare repository
<you are logged in to your server>
mkdir foo-bar.git
cd foo-bar.git/
git --bare init
git remote add origin ssh://<user>@<server>/<git directory>/foo-bar.git
git push -u origin master
git push origin master
Now, to ensure that your local branch is tracking when you do a fetch, you need to use -f option to force a new local branch to be created even though it already exists.
# Checkout the origin/master branch
git checkout origin/master
# Now we can create the local "master" branch that is tracking the remote branch
git branch -f master origin/master
# Switch back to your "master" branch
git checkout master