threads / discuss / 11672

Any command to simplify 'git fetch origin && git reset --hard origin/master'?

Subject: Any command to simplify 'git fetch origin && git reset --hard origin/master'?

## tl;dr

10 messages between Jan 19, 2008 and Jan 20, 2008.

replies: 9people: 4as markdown or json

Ping Yin· Jan 19, 2008, 05:22 UTC · lore

I often encounter the case that the origin reposotory is rebased and i make sure i want to use the origin head as my master Now I have to do $ git fetch origin && git reset --hard origin/master

Should we introduce 'git pull --force-update' or something else to do the command combination?

-- 
Ping Yin
David Symonds· Jan 19, 2008, 06:04 UTC · re: Ping Yin · lore

Re: Any command to simplify 'git fetch origin && git reset --hard origin/master'?

On Jan 19, 2008 4:22 PM, Ping Yin <pkufranky@gmail.com> wrote:
> I often encounter the case that the origin reposotory is rebased and i
> make sure i want to use the origin head as my master
> Now I have to do
> $ git fetch origin && git reset --hard origin/master

Use "git pull origin", which will do the fetch, and then merge it. If you haven't made local changes, the merge will be a fast-forward and so will get you an equivalent result.

Dave.
Junio C Hamano· Jan 19, 2008, 07:06 UTC · re: Ping Yin · lore

Re: Any command to simplify 'git fetch origin && git reset --hard origin/master'?

"Ping Yin" <pkufranky@gmail.com> writes:
> I often encounter the case that the origin reposotory is rebased and i
> make sure i want to use the origin head as my master
> Now I have to do
> $ git fetch origin && git reset --hard origin/master

The fact you are resetting means you do not have anything interesting in your own branch yourself (--hard will lose your changes and you are willing to lose it), which makes the use case much less interesting, but I can understand a workflow that is based around rebases, as in:

	$ git fetch origin && git rebase origin/master

which would be an equivalent to the resetting --hard when you do not have anything interesting in your branch but if you do have interesting commits they will be transplanted on top of the rebased upstream head.

Upcoming 1.5.4 will have "git pull --rebase origin", which is a short-hand for the above command. That is a parallel for rebase based workflow, just like "git pull origin" is a short-hand for

	$ git fetch origin && git merge origin/master
to help merge based workflow.
Ping Yin· Jan 19, 2008, 08:03 UTC · re: Junio C Hamano · lore

Re: Any command to simplify 'git fetch origin && git reset --hard origin/master'?

On Jan 19, 2008 3:06 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
> "Ping Yin" <pkufranky@gmail.com> writes:
>
> > I often encounter the case that the origin reposotory is rebased and i
> > make sure i want to use the origin head as my master
> > Now I have to do
> > $ git fetch origin && git reset --hard origin/master
>
> The fact you are resetting means you do not have anything
> interesting in your own branch yourself (--hard will lose your
> changes and you are willing to lose it), which makes the use
> case much less interesting, but I can understand a workflow that
> is based around rebases, as in:
>
>         $ git fetch origin && git rebase origin/master
>

I know 'git pull --rebase' and use it frequently. However, in the case i mentioned above, i never do any change in this local branch, i just use this branch for deployment which should always keep the same with the origin head (just like the remote tracking branch). So i need a 'fetch & reset --hard' equivalent, not the 'fetch & rebase' equivalent.

-- 
Ping Yin
Junio C Hamano· Jan 19, 2008, 08:06 UTC · re: Ping Yin · lore

Re: Any command to simplify 'git fetch origin && git reset --hard origin/master'?

"Ping Yin" <pkufranky@gmail.com> writes:
Show 22 quoted lines
> On Jan 19, 2008 3:06 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> "Ping Yin" <pkufranky@gmail.com> writes:
>>
>> > I often encounter the case that the origin reposotory is rebased and i
>> > make sure i want to use the origin head as my master
>> > Now I have to do
>> > $ git fetch origin && git reset --hard origin/master
>>
>> The fact you are resetting means you do not have anything
>> interesting in your own branch yourself (--hard will lose your
>> changes and you are willing to lose it), which makes the use
>> case much less interesting, but I can understand a workflow that
>> is based around rebases, as in:
>>
>>         $ git fetch origin && git rebase origin/master
>>
> I know 'git pull --rebase' and use it frequently. However, in the case
> i mentioned above, i never do any change in this local branch, i just
> use this branch for deployment which should always keep the same with
> the origin head (just like the remote tracking branch). So i need a
> 'fetch & reset --hard' equivalent, not the 'fetch & rebase'
> equivalent.
Unless I am misreading you, you did not read what I wrote.

If you do not have any change on that branch, "git rebase origin/master" will be equivalent to "git reset --hard origin/master".

Ping Yin· Jan 19, 2008, 08:08 UTC · re: Junio C Hamano · lore

Re: Any command to simplify 'git fetch origin && git reset --hard origin/master'?

On Jan 19, 2008 4:06 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 32 quoted lines
>
> "Ping Yin" <pkufranky@gmail.com> writes:
>
> > On Jan 19, 2008 3:06 PM, Junio C Hamano <gitster@pobox.com> wrote:
> >> "Ping Yin" <pkufranky@gmail.com> writes:
> >>
> >> > I often encounter the case that the origin reposotory is rebased and i
> >> > make sure i want to use the origin head as my master
> >> > Now I have to do
> >> > $ git fetch origin && git reset --hard origin/master
> >>
> >> The fact you are resetting means you do not have anything
> >> interesting in your own branch yourself (--hard will lose your
> >> changes and you are willing to lose it), which makes the use
> >> case much less interesting, but I can understand a workflow that
> >> is based around rebases, as in:
> >>
> >>         $ git fetch origin && git rebase origin/master
> >>
> > I know 'git pull --rebase' and use it frequently. However, in the case
> > i mentioned above, i never do any change in this local branch, i just
> > use this branch for deployment which should always keep the same with
> > the origin head (just like the remote tracking branch). So i need a
> > 'fetch & reset --hard' equivalent, not the 'fetch & rebase'
> > equivalent.
>
> Unless I am misreading you, you did not read what I wrote.
>
> If you do not have any change on that branch, "git rebase
> origin/master" will be equivalent to "git reset --hard
> origin/master".
>
But my case is that the origin head has been rewound.
-- 
Ping Yin
Johannes Schindelin· Jan 19, 2008, 11:15 UTC · re: Ping Yin · lore

Re: Any command to simplify 'git fetch origin && git reset --hard origin/master'?

Hi,
On Sat, 19 Jan 2008, Ping Yin wrote:
> I often encounter the case that the origin reposotory is rebased and i
> make sure i want to use the origin head as my master
> Now I have to do
> $ git fetch origin && git reset --hard origin/master
Just make an alias if you're too lazy to type.

Personally, I do not see much sense in it, and it is too dangerous to bless it with an option to fetch or pull.

Ciao, Dscho

Ping Yin· Jan 19, 2008, 14:03 UTC · re: Johannes Schindelin · lore

Re: Any command to simplify 'git fetch origin && git reset --hard origin/master'?

On Jan 19, 2008 7:15 PM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 14 quoted lines
> Hi,
>
> On Sat, 19 Jan 2008, Ping Yin wrote:
>
> > I often encounter the case that the origin reposotory is rebased and i
> > make sure i want to use the origin head as my master
> > Now I have to do
> > $ git fetch origin && git reset --hard origin/master
>
> Just make an alias if you're too lazy to type.
>
> Personally, I do not see much sense in it, and it is too dangerous to
> bless it with an option to fetch or pull.
>

Can any alias do this? Since a parameter 'origin' or something should be passed in. Of course i can write a very simple wrapper. I just try to figure out the better way.

> Ciao,
> Dscho
>
>
-- 
Ping Yin
Johannes Schindelin· Jan 19, 2008, 22:50 UTC · re: Ping Yin · lore

Re: Any command to simplify 'git fetch origin && git reset --hard origin/master'?

Hi,
On Sat, 19 Jan 2008, Ping Yin wrote:
Show 16 quoted lines
> On Jan 19, 2008 7:15 PM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>
> > On Sat, 19 Jan 2008, Ping Yin wrote:
> >
> > > I often encounter the case that the origin reposotory is rebased and 
> > > i make sure i want to use the origin head as my master Now I have to 
> > > do
> > >	$ git fetch origin && git reset --hard origin/master
> >
> > Just make an alias if you're too lazy to type.
> >
> > Personally, I do not see much sense in it, and it is too dangerous to 
> > bless it with an option to fetch or pull.
>
> Can any alias do this? Since a parameter 'origin' or something should be 
> passed in.
Yes.  Something like
	$ git config alias.imtoolazytotype \
		'!sh -c "git fetch $0 && git reset --hard $0/master"'

See http://git.or.cz/gitwiki/Aliases for more, especially the part about advanced aliases with arguments.

Hth, Dscho

Ping Yin· Jan 20, 2008, 08:51 UTC · re: Johannes Schindelin · lore

Re: Any command to simplify 'git fetch origin && git reset --hard origin/master'?

On Jan 20, 2008 6:50 AM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 29 quoted lines
> Hi,
>
> On Sat, 19 Jan 2008, Ping Yin wrote:
>
> > On Jan 19, 2008 7:15 PM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> >
> > > On Sat, 19 Jan 2008, Ping Yin wrote:
> > >
> > > > I often encounter the case that the origin reposotory is rebased and
> > > > i make sure i want to use the origin head as my master Now I have to
> > > > do
> > > >   $ git fetch origin && git reset --hard origin/master
> > >
> > > Just make an alias if you're too lazy to type.
> > >
> > > Personally, I do not see much sense in it, and it is too dangerous to
> > > bless it with an option to fetch or pull.
> >
> > Can any alias do this? Since a parameter 'origin' or something should be
> > passed in.
>
> Yes.  Something like
>
>         $ git config alias.imtoolazytotype \
>                 '!sh -c "git fetch $0 && git reset --hard $0/master"'
>
> See http://git.or.cz/gitwiki/Aliases for more, especially the part about
> advanced aliases with arguments.
>
wonderful!
> Hth,
> Dscho
>
>
-- 
Ping Yin

← back to recent threads