git clone from local to remote
To answer your first question, yes, you can. Suppose the remote directory is ssh://user@host/home/user/repo
. This must be a git repository, create that with git init --bare
or scp
your local repo.git
(can be created with git clone
) directory to remote. Then do:
git remote add origin ssh://user@host/home/user/repogit push --all origin
This will push all locally-existing branches to the remote repository.
To get to your next question, you should be able to do the same thing by using a different set of commands. Try these:
$ cd /var/www # or wherever$ mkdir somesite$ cd somesite/$ git init$ git --bare update-server-info$ git config receive.denycurrentbranch ignore$ cat > hooks/post-receive#!/bin/shgit checkout -f^D$ chmod +x hooks/post-receive
You would, of course, run the remote/push commands above after this step. You may have to check out a specific branch after doing so, so that the "somesite" clone on the server actually knows which branch to follow. From then on out, pushing to that repository should trigger a re-checkout of that branch.
I also ran into this issue recently and solved it as follows:
On remote server:
1: Create a directory named /tmp/bare
2: Change to that directory
3: Execute git init --bare
On local machine:
1: Change to your git project directory
2: git remote add bare ssh://user@server/tmp/bare
3: git push --all bare
4: git remote remove bare
On remote server:
1: git clone /tmp/bare /path/to/your/clone
On local machine:
1: git remote add origin ssh://user@server/path/to/your/clone
This is a little involved, but it works and does not require setting any weird flags or instructing git to override its default behaviours. It is hence quite safe.
This answer is good but I was not able to get it to work for me. The following code from this link did http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/. On the remote run
mkdir my_project.gitcd my_project.gitgit init --baregit-update-server-info # If planning to serve via HTTP
Locally on an existing repository that already has at least one commit run
git remote add origin git@example.com:my_project.gitgit push -u origin master
I hope this helps anyone that had problems with the other answer.