Search code examples
gitgithubversion-controlcollaboration

git collaborate on branch


Tom and Alice would both to collaborate on a branch of project, which is hosted on Github. Here is what happened so far:

  1. Tom forks project.
  2. Tom makes branch new-feature in his fork.
  3. Tom commits changes to new-feature.
  4. Alice forks project.
  5. Alice: git remote add toms-fork git@githum.com:Tom/project.git.
  6. Alice: git fetch toms-fork.
  7. 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?


Solution

  • 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.