Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull doesn't get new tags and new branches but git fetch does

Tags:

git

I had trouble trying to get my coworker new created tags when he told me he already pushed them up and they where up in the repo. It wasn't until I used git fetch when I could get the new tag and actually informed me about a new branch created. I knew git pull is basically git fetch & git merge so I was wondering why it wasn't getting the latest changes. Here are the two situations:

git pull origin dev
From ******.****.*****/*******
 * branch            dev        -> FETCH_HEAD
Already up-to-date.

git fetch
From ****.****.com:*******/*******
   ae06d29..958f332  master     -> origin/master
 * [new branch]      task-Q -> origin/task-Q
 * [new tag]         demo_5-21  -> demo_5-21
 * [new tag]         demo_5_27  -> demo_5_27

Was I missing something?

like image 545
VaTo Avatar asked Jun 12 '15 23:06

VaTo


2 Answers

Looking at the synopsis of git pull we see:

'git pull' [options] [<repository> [<refspec>...]]

When you run git pull origin dev you are specifying that you want to pull the refspec dev from the remote origin. Since you're specifically asking for the dev branch, no other branches or tags are pulled.

Instead, try git pull --all.

like image 148
Chris Avatar answered Oct 07 '22 01:10

Chris


Yes: 'git pull' is a 'git fetch; git merge'.

No: 'git fetch --all' will not fetch all tags by default without '--tags' ... it will fetch reachable tags, see third part of my answer below.

Likewise: 'git push' does not push tags by default without '--tags'.

Your git pull origin dev fetched only the remote dev branch. If you had typed git pull or git pull origin you would get the new branch ... depending on the configuration. What is fetched is controlled by three things, you probably took advantage of the last one:

Command line: While git pull --tags works, it won't necessarily fetch tracking branches ... and git reminds you to use git fetch --tags. This would have fetched your coworker's tags, but not any branches.

$ git pull --tags
. . .
Fetching tags only, you probably meant:
    git fetch --tags

Remote/branch fetch configuration: With bare git fetch or git fetch origin the remote and branch configuration controls behavior. These didn't come into play:

$ git config remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*

$ git config --get-regexp 'branch.master*'
branch.master.remote origin
branch.master.merge refs/heads/master

Upstream branch/tag history: According to the second paragraph of the git fetch documentation

By default, any tag that points into the histories being fetched is also fetched; the effect is to fetch tags that point at branches that you are interested in.

This means that when your coworker pushed a branch with new tags in its history, your git fetch got the new branch and the new tags.

like image 32
qneill Avatar answered Oct 07 '22 01:10

qneill