Branches and remotes

I seem to have a misunderstanding about branches and remotes. In a tabbed column on the left I see several blue branches which I have been told are my local working branches. I was working on branch bugFix_FFT, which I had just committed and pushed to origin.

Further down there are grey branches under Remotes including releaseV4.x. which I need to merge into my branch. I did not have a working copy of releaseV4.x and was about to checkout a new branch. However my co-worker said I must first perform a fetch to update releaseV4.x before I created a branch from it. I thought that the branches under remote would already be up to date since they are in the bare repository but he said that the grey releaseV4.x was what my "view" thought was the current version and needed to be updated with a fetch.

So was the fetch necessary?




1 answer

Short answer: yes.

Explanation: Branches are just lightweight pointers to commits. Each time you fetch, all new commits in the repository are added to your local repository (regardless of whether they are part of any of your local branches), and your local record is updated regarding which commits the remote branches are pointing to.

This is one of the concepts that is completely different between Git/Hg vs centralized versioning like SVN. When you checkout a remote branch to your working copy in Git/Hg (making a local branch in the process), your repo does NOT need to access the remote to download the commits for that branch, because they are already in your local repo.

Thanks, but still not quite clear.

You stated "Each time you fetch, *all* new commits in the repository are
added to your local repository". I agree that it updates my local
repositiory but my coworker said I needed to fetch to update the version of
releaseV4.x under remotes before I checked it out into a new branch on my
local. I was assuming that being under remotes meant it was not local but
at origin and fetch would only update my local copies.


Your assumption is a bit off. A branch being under remotes doesn't mean that it is not local. Rather, it means it doesn't belong to your local repository - you cannot commit directly to it. If you check it out, you create a new local branch that is configured to "track" origin's branch, and those two branches are kept in sync locally by merging (possibly fast-forward) or rebasing. Hope that helps.

Thanks again. 

I ain't the sharpest knife in the drawer but maybe my assumptions would be better if there was a user's manual.

You haven't actually specified which you use, but for Git you might check out the Git book:

One addition: if you just need to merge an origin/ branch into your own, you don't need to check it out first. You can merge the origin branch into your branch. (After a fetch to make sure the origin branch reference is up-to-date.)

I tried that with SourceTree, and its UI doesn't give you the option.

Yes, it does: - Make sure you have "all branches" and "show remote branches" is on in the main view. - Find the commit with the right flag (e.g. origin/master), right-click, merge. (There is no context-menu item if you right-click the branch name in the origin branch list, though.)

Hmm, good point. I definitely only tried the branch list.

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,129 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