0

I have been asked to create branch 1.2.1 from branch 1.2, and work on branch 1.2.1 locally. I think branch 1.2 is on the main server, but then I also read that git automatically copies the complete repository locally, so I don't know where branch 1.2 is located.

I have reviewed several questions which I think attempt to answer this, but they all give different answers, and all have replies saying it didn't work, or maybe try this instead. I need certainty on this, because experimenting just leads to me losing my work or corrupting the repository.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Yimin Rong
  • 1,890
  • 4
  • 31
  • 48

1 Answers1

2
  1. Make sure you have all the code from the remote server:

    git fetch origin

  2. Checkout the code for branch 1.2

    git checkout 1.2

  3. Create your new branch.

    git checkout -b 1.2.1

It should be that easy.

Matt Grande
  • 11,964
  • 6
  • 62
  • 89
  • 1
    This is correct. However, you *do* need to know your own branch names, and if you're not sure, ask somebody locally who knows. – Greg Hewgill Oct 21 '13 at 20:22
  • Thank you. Sorry, I tried it, but it fails at step 2. Can I undo step 1? – Yimin Rong Oct 21 '13 at 20:41
  • Step 1 can be undone if you have a reflog for it (seems enabled by default in git 1.8.1.4). Look at `git reflog origin/master` (and substitute with the appropriate names of the remote and branches). – jørgensen Oct 21 '13 at 22:16
  • 1
    However, fetching from a remote is a perfectly normal thing to do and there isn't any need to "undo" it (particularly not just because step 2 failed). – Greg Hewgill Oct 22 '13 at 03:02
  • Please understand from my viewpoint that I have lost my work and corrupted the main branch many times with git, so I've developed a sense of paranoia and dread when working with it. It makes me feel stupid. – Yimin Rong Oct 22 '13 at 13:12
  • You say it fails at step 2. What does it say? Is "2.1" the name of your branch? – Matt Grande Oct 22 '13 at 13:14
  • It's gone now, something along the lines of changes must be stashed. I tried `git stash` but that brought up more errors, so I just renamed and compressed the directory and moved it to removable media, then cloned the entire repository. I have like a dozen of these USB keys with tons of modified files I don't want to lose. – Yimin Rong Oct 22 '13 at 13:46
  • Okay, so here's why you got that error: You can't change branches when you have uncommitted changes. You should either a) commit your changes (These are good! I want to keep them!) b) stash your changes (These are okay, but not ready to be committed), or c) revert your changes (What was I thinking! Let's forget this ever happened). Hope this helps! – Matt Grande Oct 22 '13 at 13:53
  • Sorry, I think what you suggested doesn't apply any more. I was getting errors and getting paranoid so I renamed the directory, compressed and moved it to removable media, then cloned a new one. Again sorry, I just can't understand git, and don't think I ever will. – Yimin Rong Oct 22 '13 at 14:16
  • Git can be daunting, to say the least (especially if you're coming from SVN or worse, no source control experience at all). I highly recommend reading through here: http://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide?rq=1 There are lots of great links/resources in there. – Matt Grande Oct 22 '13 at 14:20