Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

View Branches in SourceTree for Subtrees

David Jacobson September 6, 2019

Just created a subtree within a master project.
Project [Project Name]
Subfolder [subtree]

I now see the SUBTREES option in the left control panel of SourceTree which is point to my git repository.  I then created a branch in JIRA but it doesn't show up within the main project or the subtree.

Am I missing a step or did I do something incorrectly when I set up the subtree? 

Looking for more guidance, examples, instructions, etc., on how to do this process.  Hopefully this is what I need to do to do what I want.

Ultimately we are trying to separate smaller projects (subtrees) that are a part of a larger project without having to mess with any other code except for the specific subtree project.

Thanks for any help or guidance you can provide me!!

1 answer

0 votes
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 6, 2019

Hi @David Jacobson,

Welcome to the Atlassian Community.

After you created your branch in Jira, did you do a Fetch in the corresponding repository? When you create a branch in Jira, it will only create it on the remote repository, it will not push it out to local clones (mainly because Git do not keep track of clones).

Note that the subtree in Sourcetree will only allow you to pull in new commits on a specified branch, it will not show all branches in the subtree. The only time you will see all branches is if you right-click on the subtree and select Edit, from here you can change which branch it should pull from/push to.

When I was putting together a Confluence page for my users about Git subtrees I found this blog post,https://medium.com/@v/git-subtrees-a-tutorial-6ff568381844, that explains how subtrees works.

David Jacobson September 6, 2019

Thanks so much Mikael.  I am very new to git and my PM has asked me to lead this process and figuring out how it works.  So sorry for the many, many questions to come.  :)

So, our master project is [Portal], separate git repo, we also have another git repo [forms].

So our file structure for development looks like this: [localhost] > portal > forms > etc...

So I have, in SourceTree, a project for Portal and a project for Forms.  I was in the Portal project and right-clicked the left menu area and selected 'add link/subtree'.  in the setup window, I selected the forms (git) repo url, 'Master' branch (Wasn't sure which to select), and the local file path [localhost] > portal > forms.

That indeed created a subtree. I can see it in the left nav area now [localhost]>forms

I then went into Jira and created a branch from the forms project and tried to check it out in sourcetree, but I wasn't sure where to check it out too as I was expecting to see the branch within the subtree, but alas it wasn't there.

I know I did something wrong here, or, many things wrong here, thank you so much for your time and guidance in helping me understand this process.  Looking forward to hearing back from you.  In the meantime, I will read the link you sent me.

David Jacobson September 6, 2019

As a caveat, we are not using the command line git process.  I was asked to find solutions that don't use command line functions.  They are trying to do this using git, bitbucket and SourceTree. :D

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 6, 2019

No worries about the many questions, that is what this Community is all for!

So, I would recommend doing all your changes in each separate subtree and then just bring it all in to your master (Portal) project when needed. You could do all the changes in Portal, but you can run into issues with that where you have a mix of commits both in your subtree and Portal. 

Regarding your branch, on your local copy of Forms, if you do a Fetch that will bring in the new branch and you should see it under origins, and from here you can check it out. It will not show up under Subtree in your Portal repository, unless you right-click and select edit to change the branch the subtree is using. A subtree can only be setup to pull from/push to a single branch.

David Jacobson September 6, 2019

Thanks again Mikael.

So, I created the branch FM-1, from the Forms repo. 

After doing that, should I check it out in SourceTree in the local Portal project or the Forms project?

I currently checked it out in the Forms project and then switched to the Portal project and did a fetch and didn't see the branch anywhere.  Then I changed the subtree to point to that newly created branch and re-did a fetch and still no branch anywhere. 

Ideas of what I may have done wrong? 


Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 6, 2019

You are not doing anything wrong, I think you just have the concept of subtrees mixed. A subtree is basically just a copy of what the repository of that subtree looked like at a specific commit. In Sourcetree you will not see any of the branches created in your subtree.

You check out FM-1 in the Forms repository, since that is where you created it. It will not be visible in the Portal repository. The branches you see in Portal will only be the ones created in that repository.

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 6, 2019

To bring any changes in that you did in FM-1 and Forms into Portal you would have to edit your subtree settings in Portal to use FM-1 as the source instead of the original branch, normally master. Once you done that you can do a pull to get the latest from Forms and the FM-1 branch. 

David Jacobson September 6, 2019

Okay, so I tried to do a PULL from my subtree and this is what I got.  Needless to say, I have no idea what it means.  :D

git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks -c credential.helper= -c credential.helper="C:/Users/DAVID~1.JAC/AppData/Local/ATLASS~1/SOURCE~1/GIT_EX~1/GIT-CR~1.EXE" subtree pull -P www\forms\telework --squash https://djacobson66@bitbucket.org/epmap/telework.git TW-17-migrate-tw-code-out-of-epmap-and-i
Working tree has modifications. Cannot add.
Completed with errors, see above.

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 6, 2019

Okay, so what the error message is telling you is that you made changes in Portal and because Git has a default disposition of keeping data unless it’s explicitly thrown away.

In order to solve this, look that the top of the history pane in Sourcetree and you should see Uncommitted changes, and that is what preventing git to pull in from the subtree. You either have to commit those changes, discard/remove them or if they are changes to existing files in the repository you could stash them. Once you do not have any uncommitted changes you should be able to do the pull successfully.

David Jacobson September 9, 2019

Thanks Mikael, that does make sense. Thank you.

However, I still am confused about the file separation and structure in regards to using SourceTree and bitBucket and which project directory do I actually work from when Jira tickets are created.  I will send you some screenshots from my project so maybe I can understand what I am doing wrong and what needs to be done.  Is that okay?

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 9, 2019

Absolutely, send those screenshots if you want.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events