2

summary:
(I'm quite new to git;)
trying to to work like described here: http://nvie.com/posts/a-successful-git-branching-model/
however I seems to miss to understand how to work with several branches (i.e. master, develop, hotfix)

  • shall I use "stash" when checking out a 3rd branch (hotfix from master, whilst in develop)
  • do I miss sth. when using "push"

In Detail:
I've created with gitolite a repos:

  • called "BE" which is from origin master
    (1st use: git push origin master)
  • added some files and pushed them
    ( git add.; git commit -m "bla"; git push )
  • then a branch origin develop
    ( git checkout -b develop master )
  • added some files and pushed them
    ( ...; git push origin develop )
  • now I'd like to create a brunch from "master" called hotfix_3.0.1
    ( git checkout -b hotfix-3.0.1 master )

=> And I get a problem:

error: Your local changes to the following files would be overwritten by checkout:
....
Please, commit your changes or stash them before you can switch branches.
Aborting

==== the question is:
how to establish working simultaneously with two branches?
shall I stash my changes in "develop" - brunch before checking out a new branch from master?

alex
  • 21
  • 1
  • Hi all,thanks to your suggestions. It seems to me (sorry) that I've forgot to to commit. (uargh, yes) this 3 steps are needed: `git add .; git commit -m "bla"; git push` - that's all. Afterwards I could change the branches as intended. So the error-message of git was telling the truth; My mistake! – alex Jul 09 '13 at 15:55

2 Answers2

0

Only one environment can be active at a time. You need to either stash (put some temporary work on hold, to retrieve it later) your changes or commit them before switching to a new branch.

If you're pretty sure about your changes, just commit them : after all, it's a dev branch and supposedly unstable (if you don't push them, they stay local and you can either revert the commit or squash it with a rebase before pushing)

Bruce
  • 6,984
  • 1
  • 23
  • 41
  • o.k. then, it seems to me, that I do not `commit` (commit && push) my dev-branch correctly! (it's a remote repos setup with gitolite) as described above (at least tried to) I've committed and pushed my dev-brunch; - is: `git push origin develop` - not enough? however git do not let me create a 3rd branch from an other (then current) branch. Any tips, how to "push" correctly? – alex Jul 09 '13 at 12:53
0

You could very well clone your repo twice, if you really need to work on two branches simultaneously.
That would avoid any issue with the checkout step.

If you are working in the same repo, then the initial push should be:

git config push.default simple
git push -u origin master
# or
git push -u origin develop

See "Why do I need to explicitly push a new branch?": that will set origin/master as an upstream branch of master, allowing you to use simply git push for all the subsequent pushed.
With the "simple" push policy, would will only push the current branch to that upstream branch.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283