Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

I have various Git projects that are on my local machine. I have a server that I would like to use as my remote Git Repository. How do I move my local Git Repositories (Projects) to my server while keeping the history intact?

Thanks!

EDIT: Thanks for all the great answers. The response I choose makes sense to my limited GIT knowledge.

EDIT #2: I noticed my original answer selection did not copy my tags. git push --mirror <path> does copy tags.

like image 773
Mausimo Avatar asked Jan 23 '12 21:01

Mausimo


People also ask

Can I create remote repository from local git?

I think you make a bare repository on the remote side, git init --bare , add the remote side as the push/pull tracker for your local repository ( git remote add origin URL ), and then locally you just say git push origin master . Now any other repository can pull from the remote repository.


2 Answers

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 
like image 181
knittl Avatar answered Oct 01 '22 01:10

knittl


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 
like image 26
Dor Shemer Avatar answered Oct 01 '22 02:10

Dor Shemer