Search code examples
gitbranch

Git switching branch


There is something I don't get yet with Git. It is branching.

So let’s say that I have a local repository A which I clone from a remote one B. So now A have the master branch checked out.

So when I push from A it goes to B master.

B is just a clone on GitHub, a clone of C.

From time to time, in order to get in sync, I pull from the C master branch.

But now the C master branch is quite broken for the time being. Since from A I had pull from C, my local A is also buggy.

So I would like from A to pull the C stable branch. How can I do it in this situation?

Do you create a new branch on A and pull from C? But since A has the C master change, I need to revert it first...


Solution

  • git fetch C
    git checkout C/stable-branch
    git checkout -b myCopy
    

    Then myCopy is a local (copied) branch of C's stable one.