Paperbag Writer
Paperbag Writer

Reputation: 823

Creating a new branch on a branch in Git

I would like to know if it is possible/good practice to git branch -b "devfeature1" if I'm on a branch already "dev".

In sourcetree I have trouble visualising this as it seems the show the branch of branch on the same branch. Am I doing it right?

Is it doing what i want to do and it's just not showing as I imagine it?

On master : git checkout -b "dev"

On dev : git checkout -b "feature1"

Visual example of what I want :

Branches visual representation

Thanks

Upvotes: 3

Views: 160

Answers (3)

borisano
borisano

Reputation: 1386

Yes, this is common practice. And since branches in Git are just pointers to commits, this won't create any internal mess or something like that.

P.S. I'd also advice you to read about common Git Workflows. Those are common good-practices in using git branches. You may consider sticking to one of those depending on your needs and team size.

Approach you are talking about is somewhat called 'Gitflow workflow' It is described in a link above, and I personally like it and stick to it whenever possible (even in personal projects, where such structure isn't necessary at all).

Here is a cheatsheet for Git Workflow that is much more clear than Atlasian's description in a link above. There are also a lot of other materials in the Internet regarding the topic. Gitflow Workflow is kind of popular nowdays.

Upvotes: 4

Igal S.
Igal S.

Reputation: 14593

It is possible and good practice. There is even a name for it - Gitflow. You can read more about it here: https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

Upvotes: 2

Seth McClaine
Seth McClaine

Reputation: 10040

That is a pretty common practice. I've worked at a few companies where the main branch is production which has a branch for test that has a branch for dev and then some devs will branch off for specific tickets say issues 313, at which point when ready issue 313 gets merged into dev, once approved dev gets merged into test, once approved test get merged into production.

Check out this google search for git branch diagram you can see its common

https://www.google.com/search?q=git+branch+diagram&espv=2&biw=2133&bih=1172&tbm=isch&imgil=U-l6OCo-1fbXGM%253A%253B8axB_4nJuSOBuM%253Bhttp%25253A%25252F%25252Fwww.rittmanmead.com%25252F2013%25252F07%25252Fmds-xml4%25252F&source=iu&pf=m&fir=U-l6OCo-1fbXGM%253A%252C8axB_4nJuSOBuM%252C_&usg=__34SFjfg-HlBeulNRlToa860biIU%3D&dpr=0.9&ved=0CDcQyjc&ei=0cZlVZCoEoaRsAWakIDYDQ#imgrc=_

Upvotes: 2

Related Questions