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

Branches and remotes

J Hite November 20, 2014

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?

 

Thanks,

jh

1 answer

0 votes
Seth
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.
November 20, 2014

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.

J Hite November 20, 2014

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.

Thanks,
jh

Seth
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.
November 20, 2014

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.

J Hite November 20, 2014

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.

Seth
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.
November 20, 2014

You haven't actually specified which you use, but for Git you might check out the Git book: http://git-scm.com/book/en/v2

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.
November 20, 2014

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

Seth
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.
November 21, 2014

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

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.
November 23, 2014

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

Seth
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.
November 24, 2014

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events