Git – making a local repository remote

You’ve started that funky new project on your PC, done a few bits, checked it into your local Git repository, but now you’ve decided to push it onto your remote repository.

Assumed that you are using ssh to connect to the remote machine.

Firstly, on the remote box, make the directory for your project, cd into it and then set it up as a git repository, like so:
git init --bare --shared
Then back in your project, where you’ve previously done a git init, git add . and git commit -m "comments", do this:
git remote add origin [user]@[git host]:[path to project dir on host]
This tells git where the remote origin is for your local project.
Then you need to push your local code into that repository, with this command:
git push origin master

This will create the repo.

There are 2 other things to be wary of:
– how to use your local repo and push/pull to the remote one.
When you first do a git pull back into your local repo, you may well get an error like this
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me either. Please
specify which branch you want to merge on the command line and
try again (e.g. 'git pull ').
See git-pull(1) for details.

To fix this, you need to do tweak the local settings … but perhaps its easiest just to clone it again and things will be set as needed.

If you often merge with the same branch, you may want to
configure the following variables in your configuration
file:

branch.master.remote =
branch.master.merge =
remote..url =
remote..fetch =

This does it quite well:

git config branch.master.remote origin && git config branch.master.merge refs/heads/master

– how to clone it, so you can push/pull too. TBD

EDIT:

This link also covers things quite well.

Leave a Reply

Your email address will not be published. Required fields are marked *