Git - How to use branches correctly

Asked

Viewed 958 times

0

I’m learning to use Git now, after long experience with SVN. I don’t understand how to use the branches For in the SVN one branch is a copy of trunk with all the files.

With that, in case I make one branch to fix a problem I can view the application running on trunk all the time. Just point the browser to the correct folder. In case I want to see the result of the adjustments I am making to branch just do the same thing, point to the folder branch.

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

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

  • cryo-um branch to a mistake (iss91), work on it a little bit
  • create a second branch to test a new way to solve the same problem (iss91v2)
  • go back to mine master and work on it for a while
  • create a new branch to work on something I’m not sure is a good idea (dumbidea)

What I don’t understand is : "when I return to my master and work on it for a while" master worked when I created the first branch (iss91)? When running my application at that moment it runs with the adjustments made in the branch iss91v2.

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

UPDATE: Doubt is how to visualize different implementations to solve a problem in different branches once, after editing the branch iss91v2, if I give a git checkout qualquer_outro_branch and run the application I will not view the result of the implementations of that branch. I will only see the system with the adjustments made in the branch iss91v2.

  • 4

    See if it helps you: http://answall.com/q/80583/101,

  • Unfortunately it did not help. This information I understood. I think the question ends up being : after I make a branch I no longer have access to the previous version unless I give a "reset" to disappear the commits I made in the branch ? Type : the project address is the same, but from the moment I create and modify a branch, when entering the address I just visualize the project with branch modifications. If I want to visualize what the project was doing before it’s not possible, because it now shows the adjustments I made to the branch. I didn’t understand how to use the toggle between one branch and another.

1 answer

3


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

Perhaps here lies the key to your difficulty. The most common Git usage patterns in general do not encourage you to work directly in your main branch. master or develop used to be collections of things that you developed in your branches and, when ready, you incorporated there.

Bringing this into the context of your question, your flow could be something like this:

  • creates a branch for an error (iss91) and works on it
  • back to the master
  • creates another branch to test another way to solve the same problem (iss91v2)
  • back to the master
  • creates a branch for something unrelated (naorel), works until ok
  • back to the master, merge into naorel, now master is one step ahead of your other branches.

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

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

$ git checkout iss91v2
$ git merge master

Now iss91v2 also has the changes you included in naorel but does not have the iss91. If you want you can test iss91 with the amendments of naorel likewise.

The history is very flexible, just know exactly what point you want to reach.

Then yes, when you are satisfied(a) you can do

$ git checkout master
$ git merge iss91v2

and go on living.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.