Move a local git repo to a remote repo

Challenge: one have a local git repo on a Linux server where a big bunch of commit’s have been done. Now one want to put all the files and commits on a remote server, for more easier sharing with other.

Here is how it might be done:

First create the remote repo. We use gitolite-admin, where we add typically:
# Explaination of the repo
repo path/to/remote/git/repo
RW+ = adminuser
RW = user1 user2 user3

then,

git push

Now, since there is already a local git repo on the server with commits, we need to switch to the remote repo.
Check that there are no remote:
git remote -v
should not show anything, then:
git remote add origin git@git.uib.no:path/to/remote/git/repo

and possible this one too:

git branch --set-upstream master origin/master

What I had to do now, was to clone the remote repo I created with gitolite-admin in another directory, create a dummyfile, and push it. Then I could push and pull the local repo.
So:
cd /tmp/
git clone git@git.uib.no:path/to/remote/git/repo
vim dummyfile
git add dummyfile
git commit -m "dummyfile" dummyfile
git push origin master

Then:
cd /back/to/the/local/repo/you/want/to/clone/to/remote
git pull
git push origin master

I guess there must be an easier way, but I am no Git master…

Or, one can also do it in this way:

cd folder/
git init
# make a lot of files, add, commit and so on..
# REMOTE GIT REPO AVAILABLE AT git@something.url.edu:sys/path/remoterepo.git
# First push files to remote repo
git push --remote git@something.url.edu:sys/path/remoterepo.git
# clone the remote repo into a new folder
cd ..
git clone git@something.url.edu:sys/path/remoterepo.git folder2/
mv folder/ folder-old/
mv folder2/ folder/
# Test, everything ok? If so:
rm -rf folder-old/

Leave a Reply

Your email address will not be published.