Search code examples
gitrepo

GIT clone branch to older commit in another directory


I have 2 directories of the same project, let call them directories A and B.

These two folder were cloned from a master git repo in another location, so they both started out with the same git repo commit.

Now A stayed with the original code and fixed a few minor bugs, and commited the changes, so A git branch looks like this:

A: (original)-(bug fix 1) - (bug fix 2) - (bug fix 3)

While B, I decided to change the look of the application but I havent commited yet. so B git branch looks like this:

B: (original)

What I would like to do is merge these 2 git repos from the original clone so I can have the following:

A: (original)-(bug fix 1) - (bug fix 2) - (bug fix 3)--------(merge both)

           \                                                    /
branch B:   \ -----------------(New version look) -------------

Solution

  • If you can push back to that repo, but you don't want to push B, you can:

    • go to your A local clone
    • add the B local clone as a remote:

      git remote add repoB ../B
      
    • fetch and merge:

      git fetch repoB
      git checkout A
      git merge repoB/B