Reputation: 150996
I thought I can do the following:
machine1 $ cd /
mkdir try-git
cd try-git
git init
machine2 $ git push ssh://[email protected]//try-git master
and that's it? machine1
will have all the files then? (machine2
's current directory is a git repo). But on machine2
, I keep on having git-receive-pack: command not found
, but both machines have the latest Git 1.7.4 installed...
update: seems like I need to add
PATH=$PATH:/usr/local/git/bin
to both machine's .bashrc
but why and won't invoking bash add more and more path to it.
Upvotes: 14
Views: 14533
Reputation: 96556
On the remote machine:
mkdir path/to/repo
cd path/to/repo
git init
git checkout -b tmp # Otherwise git will complain that master is already checked out.
On the local machine:
git add remote far_away username@remote_machine:path/to/repo
git push far_away master
Finally do git checkout master
on the remote machine. There's no need for git branch -d tmp
.
path/to/repo
is relative to $HOME
. If you want an absolute path just prepend /
, e.g. username@remote_machine:/path/to/repo
.far_away
is the name of the git "remote" - you can use anything though it probably makes sense to match the machine name, or something like upstream
or origin
.username@
is optional.Upvotes: 0
Reputation: 496892
It looks like you might have missed out on Git's notion of remotes. The top-level git remote
command helps you perform some common operations. In particular, you'll want to create a remote:
git remote add foobar username@hostname/path/to/repo.git
And now you can use that remote's name instead of the URL:
git pull foobar master
git push foobar
If you've created a repository locally, then created the authoritative "central" one (common if you're the originator of a project), you might want to give your remote the default name origin
, so that it'll feel like you cloned from that canonical repository. By default, git push
(with no arguments) pushes all matching branches to origin, so this can be pretty handy.
You may also want to set up tracking branches, for example:
git branch --set-upstream master origin/master
That will tell Git that, when you have your master branch checked out and you run git pull
(with no arguments), it should fetch and merge with origin's master branch.
Upvotes: 7
Reputation: 224651
If the remote system does not have Git in the system-default PATH (which is probably different from PATH in your login shell), then you have to tell it where to find git-receive-pack.
You mentioned the pathname /usr/local/git/bin/git-receive-pack
, so try this:
git push --receive-pack=/usr/local/git/bin/git-receive-pack ssh://user@machine1:/try-git master
The pathname specified with --receive-pack=
is the pathname of git-receive-pack on the remote system.
You can save the git-receive-pack pathname as part of a “remote” to save typing if you plan on accessing that repository many times:
git remote add machine1 ssh://user@machine1:/try-git
git config remote.machine1.receivepack /usr/local/git/bin/git-receive-pack
git config remote.machine1.uploadpack /usr/local/git/bin/git-upload-pack
Use it like this:
git push machine1 master
The remote.<remote-name>.uploadpack
configuration variable eliminates the need for the --upload-pack=
option to git fetch
(and git pull
) in the same way that remote.<remote-name>.receivepack
eliminates the need to specify --receive-pack=
with git push
.
In your specific scenario, you are pushing to a non-bare repository. You are also probably pushing to the branch that is checked out (pushing master
on machine2 to master
on machine1). Modern versions of Git will give you an error when you try to do this. You can override the warning, by setting certain configuration variables, but it is usually not the best way to operate.
Upvotes: 15
Reputation: 4343
Are you trying to push a whole repo to another machine? The easiest way would be to do a "git clone" from the destination machine to the source machine.
Upvotes: 3