How do branches work?

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

  • 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.

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?

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
Community showcase
Published Oct 23, 2018 in Sourcetree

Tip from the team: configure your repos for hosting goodness!

Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...

1,112 views 4 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you