Git - How to correctly use the branches [duplicate]

0

I'm learning how to use Git now, after a long life with SVN. I am not understanding how to use branches because in SVN a branch is a copy of trunk with all files.

With this, if I make a branch to fix a problem I can see the application running on trunk all the time. Just point the browser to the correct folder. If I want to see the result of the settings I'm doing in branch just do the same thing, I point to the branch folder.

In Git, after creating a branch and editing a file, I "lose" the view of the previous state of the application.

The example described below has been taken from "git-scm.com":

  • I create a branch for an error ( iss91 ), work on it a little
  • I create a second branch to test a new way to solve the same problem ( iss91v2 )
  • I go back to my master and work on it for a while
  • I create a new branch to work on something I do not know if it's a good idea ( dumbidea )

What I do not understand is: "when I go back to my master and work on it for a while" I no longer see how my master worked when I created the first branch ( iss91 )? When I run my application at that time, it runs with the settings made in the iss91v2 branch.

How should I use this? How does this workflow work?

UPDATE: The question is how to visualize different implementations to solve a problem in different branches since, after editing the branch iss91v2 , if I give a git checkout qualquer_outro_branch and running the application I will not see the result of the implementations of that branch . I will only see the system with the settings made in the iss91v2 branch.

    
asked by anonymous 12.12.2016 / 00:13

1 answer

3
  

I go back to my master and work on it for a while

Maybe here is the key to your difficulty. The most common Git usage patterns in general do not encourage you to work directly on your primary branch. master or develop are usually collections of things that you have developed in your branches and, when ready, you have incorporated it there.

Bringing this to the context of your question, your stream might look something like this:

  • creates a branch for an error (iss91) and works on it
  • back to master
  • create another branch to test another way to solve the same problem (iss91v2)
  • back to master
  • create a branch for something that is not related (naorel), works until it is ok
  • returns to master, gives merge in naorel , now master is one step ahead of its other branches.

Now if you want to see iss91 just checkout it. If you want to see iss91v2 just checkout it.

You then decided that iss91v2 is the best way to solve the other problem then you do:

$ git checkout iss91v2
$ git merge master

Now iss91v2 also has the changes that you included in naorel but do not have iss91 . If you want you can test iss91 with changes naorel in the same way.

History is very flexible, just know exactly where you want to go.

Then, when you're satisfied, you can do it.

$ git checkout master
$ git merge iss91v2

And follow life.

    
12.12.2016 / 02:52