开发者

Git "push" to somewhere other than "origin"

I am using Git to publish some code t开发者_如何学Goo GitHub. This is my first time using Git so I only know what I need to at the moment. I am using multiple computers at home to do changes. Can I push my changes from one computer to another before pushing to GitHub?


You can set up another remote, if the other computer has a Git or HTTP server running on it:

git remote add your-other-computer git://your.other.computer/...
git push your-other-computer master

I find it's easier to host a read-only repository over HTTP on each computer (by sharing my Git directory over Apache or IIS), then log onto the other computer and git pull.


You can push and pull from your other git repositories just like you would to Github…

git push [remote] [branch]

However, you cannot push to a checked-out branch in a non-bare repository.

In other words, if I want to push my changes in the master branch to my laptop from my desktop and my laptop already has the master branch checked out, Git will refuse to do it. This is to keep you from losing work, and because it's obtrusive to do.

Of course, if you run a bare repository (no working tree) you can push to it without any issues related to this, but then again you can't really work from within that repository without doing a clone and pushing back into it.

Dropbox, as suggested by Harpyon, isn't actually too bad an idea if you're syncing your own computers. I know some really smart developers that have been doing it for a while, sans problem.


If neither is a bare repository, it's better to pull (or fetch) than push, because you have more control over the merging. For this reason git will not permit pushing to a checked-out branch in a non-bare repository, as coreyward points out.

The best process would probably be to set up git daemon on the machine you want to pull from, and then configure a remote:

git remote add my-other-repo git://path/to/other/repo

Then you can pull from that repository:

git checkout branch-you-want-to-be-on
git pull my-other-repo


You can synchronize the repository using Dropbox. That's what I'm currently doing, and it works just fine. If not, you have to use one of the computers as a server of some sort, using e.g. SSH.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜