What is a simple way to Git Push to another machine?

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.


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.


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.

Tags:

Git