Reputation: 960
Tom and Alice would both to collaborate on a branch of project
, which is hosted on Github. Here is what happened so far:
project
.new-feature
in his fork.new-feature
.project
.git remote add toms-fork [email protected]:Tom/project.git
.git fetch toms-fork
.Alice: git checkout toms-fork/new-feature
Note: checking out 'toms-fork/new-feature'.
You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example:
git checkout -b
So, this has confused Alice (me). Do I need to make my own branch and submit a PR to Tom to merge into my branch into toms-fork/new-feature
, which will then be merged into project
?
Also, why is Alice (me) in a detached HEAD
state? Why am I not on toms-fork/new-feature
?
Upvotes: 2
Views: 5475
Reputation: 38106
You are in detached HEAD state when you checkout to toms-fork/new-feature
is caused by the branch toms-fork/new-feature
is not your locally branch.
If you and Tom are collaborate for toms-fork/new-feature
branch, you and Tom can use on the same github repo, such as [email protected]:Tom/project.git
(If it’s ok for both of you).
For private reason, you can’t have the permission of Tom’s github repo. So you need to create your local branch and submit a PR to Tom. Then Tom submit a PR to project (or both of you can submit PR to project
).
If your local changes need to based on toms-fork/new-feature
, you can use below steps:
# on master branch
git checkout -b mybranch
git rebase toms-fork/new-feature
make/commit/push your changes to toms-fork and submit a PR
Upvotes: 1
Reputation: 521239
You checked out the remote tracking branch called toms-fork/new-feature
. This left you in a detached HEAD state, which isn't want you want. Instead, you probably intended to do this:
git checkout toms-fork/new-feature
git checkout -b alice-branch # create a new branch from new-feature
Then, do all your work on this branch, and when it comes to merge your work back into new-feature
, you can issue a pull request on your alice-branch
. This assumes that you want to share new-feature
with your collaborator Tom. If you want your own branch, you could also have created one in the project
fork directly from the master
branch, e.g.
git checkout master
git checkout -b alice-branch
Then, both Tom's and your branches would eventually be merged back into project
.
Upvotes: 3