Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: move existing repository from PC to server, clone from server

I have an existing Git repository on my local machine. I would like to move that repository to my web server, then git clone on my local machine to check out my repository from the server. I'm planning on then developing on my local machine and pushing updates back to the server. I can ssh from my local machine to the server, but not vice versa. How should I go about this? I think git bundle should be used somehow, though when I tried to git clone my bundle on my server, I got a "warning: remote HEAD refers to nonexistent ref, unable to checkout" error. My local machine is running OS X, the server is running Linux.

like image 631
Sarah Vessels Avatar asked Oct 08 '10 22:10

Sarah Vessels


People also ask

What is the command to clone a repository from an existing server?

Cloning an Existing Repository If you want to get a copy of an existing Git repository — for example, a project you'd like to contribute to — the command you need is git clone .


3 Answers

On the Linux server, in a new directory do:

git init --shared --bare

Then on your local machine:

git remote add origin server:path/to/repo
git push --all origin

After that, the server will have a full copy of the repository, and you will be able to push and pull to and from it. There's no need to check out another clone from the server when you've already got one locally.

like image 52
Greg Hewgill Avatar answered Oct 18 '22 02:10

Greg Hewgill


Instead of "git push origin master" use "git push --all origin" so that you move over all branches and not just the master branch.

like image 9
Lynnthear Avatar answered Oct 18 '22 02:10

Lynnthear


How about this:

local> cd my_repo.git
local> git remote add origin user@host:/path/to/my_repo.git
local> git config branch.master.remote origin
local> git config branch.master.merge refs/heads/master
local> git push origin master

That will send the data from your local repo to your server. Then do this:

local> cd ..
local> git clone user@host:/path/to/my_repo.git my_repo2.git

Then you will have cloned from the server. When satisfied, you can get rid of the original repo, and possibly rename the second one.

like image 2
Paul Beckingham Avatar answered Oct 18 '22 02:10

Paul Beckingham