Re: git pull/merge master on other branch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kevin Ballard wrote:
> On May 9, 2008, at 1:24 AM, Johan Herland wrote:
> 
>> On Friday 09 May 2008, SungHyun Nam wrote:
>>> Hello,
>>>
>>> If I am on a branch (reguarly rebased), I don't want to switch to
>>> master branch, but merge origin into master.
>>> If I switch to master and pull and switch to branch, I have to
>>> rebuild almost of sources.
>>>
>>> How I can pull origin into master without switching to master
>>> branch?
>>
>> You can't; merging requires use of the working tree (to resolve
>> conflicts).
>>
>> However, what you can do is make a local clone of your project (cheap,
>> because it just hardlinks files from the original repo), and checkout the
>> master branch in the clone, perform the merge (after having set up the
>> same
>> origin and retrieved its contents), and then fetch (or push) the
>> result back
>> into the original repo (remember: "fetch" instead of "pull", since the
>> latter will initiate a merge with your current branch).
> 
> 
> If you know the pull will just be a fast-foward, then you can do
> something like
> 
>   git fetch origin && git update-ref master origin/master

I recommend against using update-ref...

and instead suggest using fetch to do all of the work.
Some variation of:

    git fetch origin master:master

This will only fast-forward the master branch based on the remote origin's
master branch. update-ref will blindly overwrite the master ref, if you make
a mistake and its not a fast-forward, you just lost some commits.

The above doesn't update your remotes though, maybe the following would be
correct, but I haven't tried it.

   git fetch origin && git fetch . remotes/origin/master:master



Also, I'm surprised no one mentioned the git-new-workdir script in the
contrib directory. It allows you to have multiple work directories
which share and update a single repository.

You could

    git-new-workdir <path_to_repo> <path_to_newworkdir> master
    cd <path_to_newworkdir>
    git pull

-brandon
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux