1

I have a simple question about git.

I would like to know what is the common way to use branch.

Figure out you create a branch for authentication that you don't finish or where you will add other stuff later. Then you work on another branch, for example relationship.

If now, I finish what I have to do on relationship and I want to add my stuff about authentication. Did I have to switch to the authentication branch or do I have to create another one?

Thanks

benoitr
  • 6,025
  • 7
  • 42
  • 67

3 Answers3

2

Branches are for anything that is independent. Want to work on a new feature? Make a branch. Want to work on fixing a bug that will probably take more than a few minutes to fix? Make a branch. Want to toy around with different configurations? Make a branch.

Branches in Git are very lightweight, so never be afraid to branch out and do something. When you want to bring changes back together, you simply use the git merge command to merge changes from one branch back into another.

Amber
  • 507,862
  • 82
  • 626
  • 550
  • 1
    This. Just remember to checkout the branch into which you want to merge the other. For example, say you have three branches: master, authentication, and relationship. You're in authentication. You switch to relationship and want to merge it into authentication. First checkout authentication, then git merge relationship. Now you have two branches: master and authentication. If you want to merge authentication into your master branch, you checkout master and merge authentication. (This is only a further explanation of what ssmithstone was saying.) – Preacher Feb 27 '11 at 13:26
  • 1
    Technically, you still have the relationship branch - merging doesn't remove the merged branch, it just takes what was the branch at the same and adds it to another branch. – Amber Feb 27 '11 at 20:45
1

you swtich to authentication branch and merge in your relationship branch

ssmithstone
  • 1,219
  • 1
  • 10
  • 21
1

It is as easy as merge authentication into relationship while in authentication, no need to switch. This will create a commit in relationship that brings your changes from authentication to relationship (conflicts might occur and you might need to resolve them)

git merge authentication

Other solution if you want to keep your history lineal, is o rebase, you would rebase relationship over authentication, this will go through all your commits adding them in order. In this case you might also experience conflicts. Here you have an explanation of the difference between them:

When do you use git rebase instead of git merge?

Community
  • 1
  • 1
Fernando Diaz Garrido
  • 3,995
  • 19
  • 22