2

A noob here. I've been reading for a few days about git and I understand branching and stuff but can you clarify this to me please.

What is the point of branching when I have a copy of a repository locally and I can just work on just the master which will not affect the master on the remote repository. Then I just push changes from my local master to the remote master?

Square-root
  • 853
  • 1
  • 12
  • 25
  • 1
    Possible duplicate of [When should you branch?](http://stackoverflow.com/questions/2100829/when-should-you-branch) – Whymarrh Sep 16 '16 at 13:28

3 Answers3

1

Branches allow you and others to work on multiple things at the same time. Polluting master can cause problems if you ever need to patch a bug or have uncompleted code for a new feature that isn't ready for release. Plus, pushing it to GitHub is a nice way to backup your work.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
1

The simple answer is to keep everything organized.

I usually keep a local master branch and a work branch. So that I know which code is perfect and ready to go. Then I branch out work with some features and/or bug fixes. I keep merging master with work time to time so it simply makes it easy for me to push my changes to remote.

I started this so if I got bored working on one thing I could easily jump to something else. I can just ignore the first task for a while and return to it when I get the "brain wave" for it.

You are perfectly in your rights to do what you wish on your local repository. It is a question of "To branch or Not to branch" and it will stay that way. When it comes to local branching I would simply suggest to "use the force".

So do whatever you feel that is productive.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Vraj Pandya
  • 591
  • 1
  • 9
  • 13
  • It's also useful to push a branch with work-in-progress items without affecting everyone's master – Ben Sep 16 '16 at 02:12
-1

branches may be use for testing purpose i mean for developing and production you can define both for same project.

https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

https://git-scm.com/book/en/v1/Git-Branching-What-a-Branch-Is

Alex
  • 818
  • 1
  • 8
  • 17