質問

We have a remote master on GitHub at: git@github.com:mainproject/mainproject.git and I created a fork from it by clicking on the fork button, so that it looks like this: git@github.com:myuser/mainproject.git

I'm not allowed to synchronize my remote fork into that remote master (git@github.com:mainproject/mainproject.git), I'm only allowed to synchronize the remote master into my remote fork.

In the past, I had used the following commands once because I got told so:

git remote add -t master upstream git@github.com:mainproject/mainproject.git
git fetch -a
git merge --ff-only upstream/master
git push origin HEAD

The command git branch -a showed there then:

  master
  tutorial/test1
* tutorial/test2
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/tutorial/test1
  remotes/origin/tutorial/test2
  remotes/upstream/master

The command git remote -v showed there then:

origin   git@github.com:myuser/mainproject.git (fetch)
origin   git@github.com:myuser/mainproject.git (push)
upstream    git@github.com:mainproject/mainproject.git (fetch)
upstream    git@github.com:mainproject/mainproject.git (push)

And the .git/config file showed there then:

[core]
  repositoryformatversion = 0
  filemode = false
  bare = false
  logallrefupdates = true
[remote "origin"]
  fetch = +refs/heads/*:refs/remotes/origin/*
  url = git@github.com:myuser/mainproject.git
[branch "master"]
  remote = origin
  merge = refs/heads/master
[remote "upstream"]
  url = git@github.com:mainproject/mainproject.git
  fetch = +refs/heads/master:refs/remotes/upstream/master

I had pushed my last changes with the command git push origin tutorial/test2 to my remote fork, because tutorial/test2 was and is my current branch, I'm working on it. That is how it has worked on my old computer.

On a new computer with freshly installed operating system I would like to continue to work on my project in my remote fork. I want to continue where I left off on the old computer and have already pushed the last changes from my old computer to my remote fork. I would like to continue to work in the branch tutorial/test2.

Do I only have to repeat all the Git commands, which are listed above, on the new computer again after a call of the command git clone git@github.com:myuser/mainproject.git?

Or would it be wrong and I would have to go another way now?

役に立ちましたか?

解決

Do I only have to repeat all the git commands, which are listed above, on the new computer again after a call of the command git clone git@github.com:myuser/mainproject.git?

That sounds about right.

Your new computer will get a new clone of your fork, which knows nothing about upstream remote, so you need to add that remote again.
This is what I described in "Forking vs. Branching in GitHub".

Note that I prefer working on a dedicated branch that I:

  • rebase on top of upstream/master
  • push to my fork.

That way, the pull request is done from that branch instead of master.
Each push would update the pull request automatically.
Each changes are isolated in that branch (you don't have to check if they come from upstream/master or your master, since you are not working in master)

See also:

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top