Git Workflow: Share code between computers without

2019-03-18 07:04发布

问题:

I work at a company which uses Git for our version control. We're using a hosted repo service (Beanstalk) as our internal "public" (by that I mean accessible to the whole dev team) repo. I have two computers that I normally work on for writing code. I like using some of the history rewriting features of Git, specifically rebasing and amending commits, but I really don't like using them after I've pushed something to a published branch. Yet, I need to be able to share code between these two computers, and preferably no one else.

What I'd like is an easy way to share my code between the two computers, without having to share it with everyone else. I have considered Airdrop (both computers are Macs), and ssh. What would be the suggested way of achieving this, while taking advantage of git's distributed nature?

回答1:

You can push, fetch and pull between the machines freely assuming you have ssh access between them:

git push computer2:projects/prog HEAD:tmp

or, if you are on computer2:

git pull computer1:projects/prog HEAD

or

git fetch computer1:prj/prog branch1:t1
git fetch computer1:prj/prog branch2:t2
git merge t1 t2

or

git fetch computer1:prj/prog branch1 branch2 branch3
git merge FETCH_HEAD

and so on... See git help fetch for more examples.



回答2:

I don't see why you cannot create temp working branches that are clearly indicated as such on the remote repo, but if you want an alternative and both computers are connected by network and accessible via ssh, you could possibly set up either or both of them as additional remotes and push from one to the other in any direction. It may be confusing to get it right the first time though as you do not want to push to the wrong remote.



回答3:

You can run an instant git server on one of the machines, either using git-daemon or something like this: https://gist.github.com/1525217



标签: git workflow