Peter D
Peter D

Reputation: 51

Github: getting a new development branch into my fork

I thought I had git pretty waxed, but I am a bit stymied with this problem.

Here is the picture: I forked 'develop' branch from a project into my own github repo, cloned to local, created git-flow feature, did stuff and published. All fine.

In the meantime, the original project changed to a new develop branch (call it 'develop2') so my published feature could not be pulled into the main project.

So - on advice - I created a local 'develop2' branch, deleted my local 'develop' branch, pulled 'develop2' from the main project repo, and then merged this with my local feature. All fine, EXCEPT... my personal github repo still has the old 'develop' branch and the feature based on that branch.

So , my question is what do I do now? A couple of options I have considered:

  1. Delete my 'develop' fork in entirety on github, fork 'develop2' from the main project , then pull this to my local repo and merge, then publish my feature again and issue a pull request. (Uncertainty tho: would I need to clone rather than pull the new fork so it had the correct origin..)
  2. Delete the 'develop' branch on origin and the feature, push new develop2 branch, and so on
  3. Force Push my 'develop2' branch to origin develop, then rename it, and do the same with the feature..

If anything goes wrong though I could get stuck with having to redo a whole lot of stuff which would be tiresome to say the least. any advice from gurus out there?

Upvotes: 5

Views: 1467

Answers (1)

dahlbyk
dahlbyk

Reputation: 77620

You absolutely don't need to redo stuff - Git is well-equipped to deal with this sort of problem.

First, forks on GitHub are the entire repository, so deleting your "'develop' fork" doesn't really mean anything - you just need to bring the upstream develop2 changes into your fork. I suggesting adding a remote called upstream to easily fetch changes from the repository from which I forked.

Now assuming you added upstream, a git fetch should pull down upstream/develop2 into your local repository. I would undo your merge (likely git reset --hard develop~), create a develop2 branch from there for consistency, then rebase your local develop2changes onto upstream/develop2: git rebase --onto upstream/develop2 upstream/develop develop.

Before:

              X---Y---Z upstream/develop2
             /
            |           H---I---J  develop, develop2
            |          /
            | E---F---G  upstream/develop
            |/
A---B---C---D

After:

                        H'--I'--J' develop2
                       /
              X---Y---Z upstream/develop2
             /
            |           H---I---J  develop
            |          /
            | E---F---G  upstream/develop
            |/
A---B---C---D

Upvotes: 3

Related Questions