How do I move my local Git repository to a remote Git repository

On your server create the git repositories as bare repository

git init --bare repo.git

then, push the commits of your local repository

git push --mirror ssh://yourserver/~/repo.git

First, create a git repo on your server

git init --bare /path/to/repo

Then add the remote repo to your local one (ssh:// or https://)

git remote add origin ssh://server/path/to/repo

And, push files/commits

git push origin master

And finally, push tags

git push origin --tags

There is a good tutorial on Ralf Wernders blog. Assuming you know how to create a repository on the server, or that has already been done:

git remote add <remote> <url>

To add a remote to your local repository. <remote> is the name of the remote (often "origin"). <url> is the url to your repository with write access (like git@...)

git push <remote> <branch>

To move the commits over to the origin. <branch> is the branch you're pushing (often "master").


Create a git repository on the server (you can use gitolite/gitosis or just a normal user account + pubkey ssh auth), add the server to your local git repository using

git remote add name url

and use git push -u name master (-u marks the current branch as tracking so you can just git pull instead git pull name master).

On the server side (debian based system):

adduser --system --home /home/git --bash /bin/bash git
su - git
mkdir .ssh
cat yourkey.pub > .ssh/authorized_keys

Now, create a new bare repository for each local repository using

mkdir projectName
cd projectName
git init --bare

After that, the url would be git@yourserver:projectName.


If you have a stand-alone local working tree repository (a folder with a ".git" folder inside) that you want to add a remote to:

  1. Create a new empty repository in the remote.
  2. In the local repository, set the new remote as the origin:

    cd localrepo

    git remote add origin REMOTEURL #(verify with git remote -v)

  3. Push all local branches to the remote, and set each local branch to track the corresponding remote branch:

    git push --all --set-upstream origin #(verify with git branch -vv)

  4. Push all local tags to the remote:

    git push --tags origin

At this point the local repository will act just like it had been cloned from the remote.


If you have a bare local repository (a folder with a name ending in .git) that you just want to copy to a remote:

  1. Create a new empty repository in the remote.
  2. In the local repository, push all of its branches to the remote

    cd localrepo.git

    git push --all REMOTEURL

  3. Push all local tags to the remote:

    git push --tags REMOTEURL