sandalone
sandalone

Reputation: 41749

Checkout back to master before making a new branch or not?

Let's say I have 10 tasks and want to create a new Git branch for each task. Each task uses it's own class so there will not be situation that task10 needs a code from task8.

Should I do like this:

  1. do some coding
  2. create a branch with task name and commit to it
  3. continue coding and when done create a branch with task name and commit to it
  4. continue like this till end

Or the proper way is:

  1. do some coding
  2. create a branch with task name and commit to it
  3. checkout Master and continue coding. when done create a branch with task name and commit to it
  4. checkout to Master and do more coding and continue like this till end

Which one is proper approach?

If the FIRST approach is the corrent one, should new branch be a branch of master or a new branch should be a branch of the previous task?

Upvotes: 0

Views: 32

Answers (1)

Anshul Goyal
Anshul Goyal

Reputation: 76837

If all your tasks are independent, then they should each branch off from master, so the second approach will be suitable. If two tasks are mutually related, they can usually be combined into a single task, independent of all others.

The flow is similar to your second approach, with some variation:

  1. Checkout master
  2. Create a new branch task_1
  3. Do some coding for the task on branch
  4. Commit to branch task_1
  5. Repeat from step 1 for all subsequent tasks

While it is true that uncommitted changes can be committed later to a new branch in git, I prefer creating a new task branch before starting the code, so that any changes etc I might need to make to the branch stay on that branch, and other branches (including master) remain unaffected. Preventing any accidental rewrite of master branch's history becomes all the more critical since it is the reference branch for all other branches. The other important advantage is you can work on multiple tasks simultaneously.

Upvotes: 1

Related Questions