# git push requires a subsequent git reset --hard ?

6 messages from 2008-07-01 to 2008-07-04. Participants: Neshama Parhoti, Jeff King, Jakub Narebski, Dmitry Potapov.
Thread: https://gitlist.dev/t/14248

## Neshama Parhoti, 2008-07-01 16:51

Subject: git push requires a subsequent git reset --hard ?
Message-ID: <912ec82a0807010951j9e970f2k9624682b33c8af7d@mail.gmail.com>
URL: https://gitlist.dev/e/912ec82a0807010951j9e970f2k9624682b33c8af7d%40mail.gmail.com

```
Hi all,

I took with me a copy of a local repository to a week away from my station
(just rsync'ed it to my laptop).

On my return, I just "git push myuser@my-station:/my/git/repo" from my laptop.
It seemed to work with no probs.
On my station the git repo got the new commits, as I can see in
git-log, but the actual files were left untouched.

So I need to do something like "git reset --hard HEAD" to get
the changes into the local files.

Is that considered normal ?

or did I do something wrong ?

Thanks,
pnesh

```

## Jeff King, 2008-07-01 17:19

Subject: Re: git push requires a subsequent git reset --hard ?
Message-ID: <20080701171913.GA8911@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20080701171913.GA8911%40sigill.intra.peff.net
In-Reply-To: <912ec82a0807010951j9e970f2k9624682b33c8af7d@mail.gmail.com>

```
On Tue, Jul 01, 2008 at 07:51:26PM +0300, Neshama Parhoti wrote:

> On my return, I just "git push myuser@my-station:/my/git/repo" from my laptop.
> It seemed to work with no probs.
> On my station the git repo got the new commits, as I can see in
> git-log, but the actual files were left untouched.
> 
> So I need to do something like "git reset --hard HEAD" to get
> the changes into the local files.
> 
> Is that considered normal ?
> 
> or did I do something wrong ?

See:

  http://git.or.cz/gitwiki/GitFaq#head-b96f48bc9c925074be9f95c0fce69bcece5f6e73

  and

  http://git.or.cz/gitwiki/GitFaq#head-46de97a5ac549d3adf406c22674b3325ae25d09c

What you did is OK, but there is a better way to do it.

-Peff

```

## Jakub Narebski, 2008-07-01 17:29

Subject: Re: git push requires a subsequent git reset --hard ?
Message-ID: <m3vdzpfr16.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m3vdzpfr16.fsf%40localhost.localdomain
In-Reply-To: <912ec82a0807010951j9e970f2k9624682b33c8af7d@mail.gmail.com>

```
"Neshama Parhoti" <pneshama@gmail.com> writes:

> I took with me a copy of a local repository to a week away from my station
> (just rsync'ed it to my laptop).
> 
> On my return, I just "git push myuser@my-station:/my/git/repo" from my laptop.
> It seemed to work with no probs.
>
> On my station the git repo got the new commits, as I can see in
> git-log, but the actual files were left untouched.
> 
> So I need to do something like "git reset --hard HEAD" to get
> the changes into the local files.
> 
> Is that considered normal ?

This is considered normal.  Push would never touch index nor working
area (although if you are the only user, and you know what you are
doing, you can add "git reset --hard HEAD" to post-receive hook).  It
is the only way: "push" cannot be opposite of "pull" and do a merge
because there is nobody to resolve conflict on remote side.

So you should either do mirroring (1:1 refspec) push into bare
repository (without working directory), or push into remotes section,
remotes/satellite or remotes/mothership, like shown in GitFaq, below.

See also:
* "Why won't I see changes in the remote repo after "git push"?"
  http://git.or.cz/gitwiki/GitFaq#head-b96f48bc9c925074be9f95c0fce69bcece5f6e73
* "How would I use "git push" to sync out of a firewalled host?"
  http://git.or.cz/gitwiki/GitFaq#head-46de97a5ac549d3adf406c22674b3325ae25d09c
-- 
Jakub Narebski
Poland
ShadeHawk on #git

```

## Dmitry Potapov, 2008-07-02 13:36

Subject: Re: git push requires a subsequent git reset --hard ?
Message-ID: <20080702133606.GP5737@dpotapov.dyndns.org>
URL: https://gitlist.dev/e/20080702133606.GP5737%40dpotapov.dyndns.org
In-Reply-To: <m3vdzpfr16.fsf@localhost.localdomain>

```
On Tue, Jul 01, 2008 at 10:29:38AM -0700, Jakub Narebski wrote:
> 
> This is considered normal.  Push would never touch index nor working
> area (although if you are the only user, and you know what you are
> doing, you can add "git reset --hard HEAD" to post-receive hook).

Doing "reset --hard" makes all your uncommit changes to be lost.
OTOH, if you push on the local branch assotiated with HEAD then
recovering all uncommit changes later will not be easy either. So,
I wonder, if git push should require --force if you want to push
to the HEAD branch of a non-bare repo. It will be at least some
warning (especially for novices) to not to do that, and those who
really want to understand what they are doing can use --force.

Dmitry

```

## Dmitry Potapov, 2008-07-02 13:45

Subject: Re: git push requires a subsequent git reset --hard ?
Message-ID: <37fcd2780807020645h463cf232oba7886cda6d7a768@mail.gmail.com>
URL: https://gitlist.dev/e/37fcd2780807020645h463cf232oba7886cda6d7a768%40mail.gmail.com
In-Reply-To: <m3vdzpfr16.fsf@localhost.localdomain>

```
On Tue, Jul 01, 2008 at 10:29:38AM -0700, Jakub Narebski wrote:
>_
> This is considered normal.  Push would never touch index nor working
> area (although if you are the only user, and you know what you are
> doing, you can add "git reset --hard HEAD" to post-receive hook).

Doing "reset --hard" makes all your uncommitted changes to be lost.
OTOH, if you push on the local branch associated with HEAD then
recovering all uncommitted changes later will not be easy either. So,
I wonder, if git push should require --force to push to HEAD of a
non-bare repository. It will be at least some warning (especially for
novices) to not to do that, and those who understand what they are
doing can use --force.

Dmitry

```

## Neshama Parhoti, 2008-07-04 13:25

Subject: Re: git push requires a subsequent git reset --hard ?
Message-ID: <912ec82a0807040625h3d4518bo270089cb5995aec6@mail.gmail.com>
URL: https://gitlist.dev/e/912ec82a0807040625h3d4518bo270089cb5995aec6%40mail.gmail.com
In-Reply-To: <20080702133606.GP5737@dpotapov.dyndns.org>

```
Thank you all for the replies !

I think git has one of the most supportive and friendly community !

```
