git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Qn about git pull and git fetch
@ 2010-09-28 16:59 suvayu ali
  2010-09-28 17:33 ` Brian Gernhardt
  0 siblings, 1 reply; 5+ messages in thread
From: suvayu ali @ 2010-09-28 16:59 UTC (permalink / raw)
  To: git

Hi everyone,

This is my first post to the list. I am a new (few months now) git
user and I use it for source code and notes for my research projects.
I noticed something during the course of my use. 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. So when I fire up gitk like
this, `gitk --all &' I don't see the latest commits for origin/master.
I have to manually run `git fetch origin' or `git remote update
origin' to see the updated commits in gitk.

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?

-- 
Suvayu

Open source is the future. It sets us free.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Qn about git pull and git fetch
  2010-09-28 16:59 Qn about git pull and git fetch suvayu ali
@ 2010-09-28 17:33 ` Brian Gernhardt
  2010-09-28 19:09   ` suvayu ali
  2010-09-28 19:51   ` Eric Raible
  0 siblings, 2 replies; 5+ messages in thread
From: Brian Gernhardt @ 2010-09-28 17:33 UTC (permalink / raw)
  To: suvayu ali; +Cc: git


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Qn about git pull and git fetch
  2010-09-28 17:33 ` Brian Gernhardt
@ 2010-09-28 19:09   ` suvayu ali
  2010-09-28 19:51   ` Eric Raible
  1 sibling, 0 replies; 5+ messages in thread
From: suvayu ali @ 2010-09-28 19:09 UTC (permalink / raw)
  To: Brian Gernhardt; +Cc: git

Hi Brian,

On 28 September 2010 10:33, Brian Gernhardt <brian@gernhardtsoftware.com> wrote:
>
> 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.
>

That explains it! I was overriding the default hence it didn't track
the remote branches as expected. Following the steps you mentioned
above confirmed that. On doing just `git pull' gave me the behaviour I
was expecting in the first place. :)

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

Thanks a lot for pointing me to these. I am using git v1.7.0.4,
v1.7.2.3 and v1.7.2.2. The above utilities will be very helpful in the
future to configure exactly how I want my repository to behave.

> ~~ Brian
>



-- 
Suvayu

Open source is the future. It sets us free.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Re: Qn about git pull and git fetch
  2010-09-28 17:33 ` Brian Gernhardt
  2010-09-28 19:09   ` suvayu ali
@ 2010-09-28 19:51   ` Eric Raible
  2010-09-28 20:01     ` Brian Gernhardt
  1 sibling, 1 reply; 5+ messages in thread
From: Eric Raible @ 2010-09-28 19:51 UTC (permalink / raw)
  To: Brian Gernhardt; +Cc: suvayu ali, git

On 11:59 AM, Brian Gernhardt wrote:
> 

> 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

Seems to me that to be equivalent, the first should be:

	git branch --set-upstream master origin/master

or the second should be:

	git config branch.master.merge refs/heads/next

Eh?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Qn about git pull and git fetch
  2010-09-28 19:51   ` Eric Raible
@ 2010-09-28 20:01     ` Brian Gernhardt
  0 siblings, 0 replies; 5+ messages in thread
From: Brian Gernhardt @ 2010-09-28 20:01 UTC (permalink / raw)
  To: Eric Raible; +Cc: suvayu ali, git


On Sep 28, 2010, at 3:51 PM, Eric Raible wrote:

> On 11:59 AM, Brian Gernhardt wrote:
>> 
> 
>> 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
> 
> Seems to me that to be equivalent, the first should be:
> 
> 	git branch --set-upstream master origin/master
> 
> or the second should be:
> 
> 	git config branch.master.merge refs/heads/next
> 
> Eh?

Oops.  I had forgotten to change the first one after some experimenting on the git.git repo.  I had meant

$ git branch --set-upstream master origin/master

Far more repos have a master branch than a next one.

~~ Brian

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-09-28 20:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-28 16:59 Qn about git pull and git fetch suvayu ali
2010-09-28 17:33 ` Brian Gernhardt
2010-09-28 19:09   ` suvayu ali
2010-09-28 19:51   ` Eric Raible
2010-09-28 20:01     ` Brian Gernhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).