git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Qn about git pull and git fetch

From
Brian Gernhardt <brian@gernhardtsoftware.com>
Date
Sep 28, 2010, 17:33 UTC
Message-ID
<9732E43E-124D-4145-A289-2E78F2277ACE@gernhardtsoftware.com>
In-Reply-To
<AANLkTi=-UU8X-7h8c4=UENRwNe+G2xGy54YhvWPnnY7y@mail.gmail.com>
On Sep 28, 2010, at 12:59 PM, suvayu ali wrote:
> If I have a remote tracking repository, and I do a `git pull
> origin master', the latest changes are merged into my currently
> checked out branch. But the references to the remote repo are not.
> This is not an inconvenience for me, just a little puzzling since the
> man page says git pull runs `git fetch' followed by `git mege'. Just
> out of curiosity, is there any reason for this choice?
`git pull origin master` does the following:
- `git fetch origin master` will fetch the master branch from remote
   origin into FETCH_HEAD
- `git merge` will then merge FETCH_HEAD into HEAD

It sounds like what you want is to get your branch as a tracking branch. If you see the following in `git remote show origin`:

[...]
  Local branch configured for 'git pull':
    master merges with remote master
[...]

Then all you have to do is `git pull`. It will update all tracking branches for origin, then merge origin/master into master. The command `git pull origin master` is telling git to override whatever defaults it has and merge the master branch from remote origin into your current HEAD.

Your branches should be set to track automatically but if they didn't for some reason and are using v1.7.0 or newer, you can:

$ git branch --set-upstream master origin/next Branch master set up to track remote branch next from origin. $ git pull

If you're using git prior to v1.7.0, you can instead:

$ git config branch.master.remote origin $ git config branch.master.merge refs/heads/master $ git pull

(Note: You only have to use `git branch --set-upstream` or the `git config ...` lines once, not before every pull.)

~~ Brian
Previous: suvayu aliNext: suvayu ali
Message 2 of 5 in “Qn about git pull and git fetch”
  1. suvayu aliSep 28, 2010
  2. Brian GernhardtSep 28, 2010
  3. suvayu aliSep 28, 2010
  4. Eric RaibleSep 28, 2010
  5. Brian GernhardtSep 28, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.