开发者

git push and distributed workflows

Alice and Bob are trying to work on the same project. Here's what we've done so far.

Bob:

mkdir myproject
cd myproject
echo "Hello" > readme.txt
git init
git add readme.txt
git commit -m "Initial Commit"

Alice:

git init
git remote add bob ssh://bob/home/bob/projects/myproject
git pull bob
git checkout remote/bob/master -b bobsMaster
echo "Hello again" >> 开发者_运维百科readme.txt
git add readme.txt
git commit -m "Improving readme"
git push bob bobsMaster

Now this is where we're stuck. The push succeeds but I have no idea where Alice's commit has gone. When Bob types git log from his master branch, Alice's commit is nowhere to be found.

Are we going about the distributed workflow in completely the wrong way? How should Alice and Bob work together on the same branch? Note that we have no central location to host our repos so we want to work entirely distributed.

Edit:

We're going to go with the pull only workflow as suggested. The reason we didn't spot the bobsMaster branch in Bob's repo is because we assumed that appeared from doing an earlier pull. Thanks for the answers!


Bob should have a bobsMaster branch created. If you want to push bobsMaster to Bob's master branch use this:

git push bob bobsMaster:master

In your workflow it's much better that Bob and Alice pull from other's repo, as pushing to a non-bare repo is not recommended.


You pushed the changes to bobsMaster and not to master. Thus Bob must merge

git checkout master
git merge bobsMaster


Regarding the "missing commit":

git log --branches

should be enough for you to see Alice's commits (since they have been done in a different branch 'bobsMaster' than yours 'master')


The commit was pushed to a new remote branch called bobsMaster in bob repository (the branch was created by git push bob bobsMaster).

The last argument in that command specifies remote refspec - if it's not found on the remote side, it's being created. bob repository had only one branch (master), so by pushing to bobsMaster you created that branch in Bob's repo.

You should use git push bob master to push your changes to Bob's master branch.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜