How do branches work?

OC2PS February 19, 2015

There is a public repo A on github. I have cloned it as B on github.

Using SourceTree, I have cloned it locally.

What I want to do is make some changes D, E, F and send pull requests to original repo A.

However, if I make commit D and push to B, then create a pull request to A, then make commit E and push to B and then create a pull request to A, then the second pull request includes both D and E, which is problematic.

I imagine that this could be resolved by using branches, but not sure how.

Also, in SourceTree if I create a branch, then it doesn't seem like additional files are created in local clone - so how do I know which branch I am working in?

1 answer

1 vote
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 19, 2015
  • A pull request is always between branches. If you want D and E to be in separate pull requests, create a branch for each of them (from the commit before D).
  • On the left side (in the gray part) in the Branches section, one of the branch names is bold. That is the branch you are working on. (Double-clicking any other will put you on that branch.)
  • In Git a branch means "a commit and all of its ancestors", so two branches can have exactly the same content if they point to the same commit. When you create a new branch, it points to the same commit as the parent branch. (Unless you create it from an older commit not at the tip of one of the branches.)
  • You might want to read this.
OC2PS February 19, 2015

Okay, so lets say I create 3 new branches, and work on 3 ideas. Then, to create a pull request for A, do I need to merge these requests into master branch of B (which would probably create the same problem as not having branches) or can I send pull requests to upstream directly from branches C, D, and E?

Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 19, 2015

You can have a PR from C, D, E in your fork to the master branch in the original repo.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events