简体   繁体   English

在2台不同的机器和github之间使用git

[英]Using git between 2 different machines and github

Lately, if I do: 最近,如果我这样做:
1. git push origin master (on my laptop) 1. git push origin master(在我的笔记本电脑上)
2. git pull origin master (on my Mac) 2. git pull origin master(在我的Mac上)
3. git status (on my Mac) 3. git状态(在我的Mac上)

I see 'your branch is ahead of 'origin/master' by 6 commits'. 我看到“您的分支比“源/主”要早6次提交”。 Since I haven't made any commits on the Mac, this seems to be an error; 由于我没有在Mac上进行任何提交,因此这似乎是一个错误; or something I don't quite understand. 或我不太了解的东西。

If I then do: 如果我那么做:
4. git push origin master (on my Mac) 4. git push origin master(在我的Mac上)

The ahead of origin/master message goes away. 原始/主控消息的前面消失了。

Note that in the above steps, I have made no commits/modifications on the Mac, between steps 1 & 2. 请注意,在上述步骤中,在步骤1和2之间,我没有在Mac上进行任何提交/修改。

It's happening all the time at the moment - should I be worried, or is there a reasonable explanation? 此刻一直在发生-我应该担心,还是有一个合理的解释?

Stop typing git pull origin master . 停止输入git pull origin master That instructs git to pull the contents of the master branch on the origin repo into your local branch, completely bypassing the remote-tracking branch. 这指示git将原始回购上master分支的内容拖入本地分支,完全绕开了远程跟踪分支。 Instead you should just type git pull . 相反,您应该只键入git pull This will pull the branch set in branch.master.merge (assuming "master" is checked out) from the remote repo and use it to update the remote-tracking branch, and then it will merge that remote-tracking branch into your local branch. 这将从远程存储库中branch.master.merge的分支集(假设已检出“ master”),并使用它来更新远程跟踪分支,然后它将该远程跟踪分支合并到本地分支中。

To clarify how it works, git pull <args> runs git fetch <args> and then uses git-merge to merge the fetched branch(es) into the current branch. 为了阐明其工作方式, git pull <args>运行git fetch <args> ,然后使用git-merge将获取的分支合并到当前分支中。 If you specify git fetch , git will fetch the default remote and update the remote-tracking branches, at which point git-pull will merge in the correct branch. 如果指定git fetch ,则git将获取默认的远程服务器并更新远程跟踪分支,此时git-pull将合并到正确的分支中。 But if you specify git fetch origin master , git will fetch the master branch of the origin repo and store it in FETCH_HEAD without updating the remote-tracking branches. 但是,如果您指定git fetch origin master ,则git将获取origin repo的master分支并将其存储在FETCH_HEAD中,而无需更新远程跟踪分支。 You can verify this yourself by typing git fetch origin master (assuming there are remote commits you don't have). 您可以通过键入git fetch origin master来自己验证(假设您没有远程提交)。 The end result of the fetch should be a line like 提取的最终结果应为

 * branch            master     -> FETCH_HEAD

This tells you that the remote branch "master" was fetched and stored in FETCH_HEAD. 这告诉您已获取远程分支“ master”并将其存储在FETCH_HEAD中。 On the other hand if you simply type git fetch origin you should see something more like 另一方面,如果您只是键入git fetch origin那么您应该会看到类似

 * branch            master     -> origin/master

This tells you that the remote branch "master" was fetched and stored in the local remote-tracking branch "origin/master". 这告诉您已获取远程分支“ master”并将其存储在本地远程跟踪分支“ origin / master”中。

Just use git push , but before configure it 只需使用git push ,但在配置它之前

git config -- global push.default matching/upstream git config-全局push.default匹配/上游

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM