Re: Qn about git pull and git fetch
- From
suvayu ali <fatkasuvayu+linux@gmail.com>
- Date
- Sep 28, 2010, 19:09 UTC
- Message-ID
- <AANLkTin1F+y1LZ8VQse_+NZP1pJuS9bnKHb4=23un29k@mail.gmail.com>
- In-Reply-To
- <9732E43E-124D-4145-A289-2E78F2277ACE@gernhardtsoftware.com>
Hi Brian,
On 28 September 2010 10:33, Brian Gernhardt <brian@gernhardtsoftware.com> wrote:
Show 29 quoted lines
> > 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. :)
Show 16 quoted lines
> 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.