# Commit changes to remote repository

4 messages from 2012-01-13 to 2012-01-17. Participants: ruperty, Carlos Martín Nieto, Matthieu Moy, Junio C Hamano.
Thread: https://gitlist.dev/t/29361

## ruperty, 2012-01-13 20:29

Subject: Commit changes to remote repository
Message-ID: <1326486589088-7185551.post@n2.nabble.com>
URL: https://gitlist.dev/e/1326486589088-7185551.post%40n2.nabble.com

```
Being new to git I am probably not doing things correctly so pointers in the
right direction would be useful.

What I want to do make changes on my laptop and commit them to a remote
repository. Here is what I have done,

1. Created a repository on my remote linux host, in a folder of cource code,
by,

   git init
   git add *
   git commit

2. On my laptop I did a git clone pointing by ssh to the remote repo which
downloaded all the files to my local system.

3. I changed a file locally and did a commit.

4. I then wanted to update the remote repo with my change, which I did with
a git push, but that didn't work, getting this error,

    remote: error: refusing to update checked out branch:
refs/heads/master[K
    remote: error: By default, updating the current branch in a non-bare
repository[K.......


What am I doing wrong?

I was following the tutorial at
http://book.git-scm.com/3_distributed_workflows.html

I did search for this issue in this list but didn't understand the
responses.

Rupert


--
View this message in context: http://git.661346.n2.nabble.com/Commit-changes-to-remote-repository-tp7185551p7185551.html
Sent from the git mailing list archive at Nabble.com.

```

## Carlos Martín Nieto, 2012-01-14 11:31

Subject: Re: Commit changes to remote repository
Message-ID: <20120114113141.GG2850@centaur.lab.cmartin.tk>
URL: https://gitlist.dev/e/20120114113141.GG2850%40centaur.lab.cmartin.tk
In-Reply-To: <1326486589088-7185551.post@n2.nabble.com>

```
On Fri, Jan 13, 2012 at 12:29:49PM -0800, ruperty wrote:
> Being new to git I am probably not doing things correctly so pointers in the
> right direction would be useful.
> 
> What I want to do make changes on my laptop and commit them to a remote
> repository. Here is what I have done,
> 
> 1. Created a repository on my remote linux host, in a folder of cource code,
> by,
> 
>    git init
>    git add *
>    git commit
> 
> 2. On my laptop I did a git clone pointing by ssh to the remote repo which
> downloaded all the files to my local system.
> 
> 3. I changed a file locally and did a commit.
> 
> 4. I then wanted to update the remote repo with my change, which I did with
> a git push, but that didn't work, getting this error,
> 
>     remote: error: refusing to update checked out branch:
> refs/heads/master[K
>     remote: error: By default, updating the current branch in a non-bare
> repository[K.......
> 
> 
> What am I doing wrong?

You're trying to push to a non-bare repository and change the
currently active branch, which can cause problems, so git isn't
letting you. There's an explanation of bare and non-bare at
http://bare-vs-nonbare.gitrecipes.de/ but the short and sweet is that
you should init the repo you want to use as the central point with
--bare and do modifications locally and then push there.

   cmn

```

## Matthieu Moy, 2012-01-14 14:27

Subject: Re: Commit changes to remote repository
Message-ID: <vpqboq6fjfy.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqboq6fjfy.fsf%40bauges.imag.fr
In-Reply-To: <20120114113141.GG2850@centaur.lab.cmartin.tk>

```
Carlos Martín Nieto <cmn@elego.de> writes:

> You're trying to push to a non-bare repository and change the
> currently active branch, which can cause problems, so git isn't
> letting you. There's an explanation of bare and non-bare at
> http://bare-vs-nonbare.gitrecipes.de/ but the short and sweet is that
> you should init the repo you want to use as the central point with
> --bare and do modifications locally and then push there.

An alternative is to push to a temporary, non-checked-out branch.

I sometimes do

  laptop$ git push desktop HEAD:incomming

and then

  desktop$ git merge incomming

The push does not disturb the worktree on the desktop, and the merge is
done manually on the receiving machine.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

```

## Junio C Hamano, 2012-01-17 00:12

Subject: Re: Commit changes to remote repository
Message-ID: <7vpqejtcep.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vpqejtcep.fsf%40alter.siamese.dyndns.org
In-Reply-To: <vpqboq6fjfy.fsf@bauges.imag.fr>

```
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> Carlos Martín Nieto <cmn@elego.de> writes:
>
>> You're trying to push to a non-bare repository and change the
>> currently active branch, which can cause problems, so git isn't
>> letting you. There's an explanation of bare and non-bare at
>> http://bare-vs-nonbare.gitrecipes.de/ but the short and sweet is that
>> you should init the repo you want to use as the central point with
>> --bare and do modifications locally and then push there.
>
> An alternative is to push to a temporary, non-checked-out branch.

Or more generally, treat such a push as if you are pulling in the opposite
direction. So in this example,

> I sometimes do
>
>   laptop$ git push desktop HEAD:incomming
>
> and then
>
>   desktop$ git merge incomming

you pretend as if you are running "git pull" on your desktop in order to
integrate the work done on your laptop. If you did

    desktop$ git pull laptop

you would store where the branches on the laptop are in the remote
tracking branches for "laptop" remote in your desktop's repository.

So a good way to simulate that would be:

    laptop$ git push desktop master:refs/remotes/laptop/master

and then run:

    desktop$ git merge laptop/master

> The push does not disturb the worktree on the desktop, and the merge is
> done manually on the receiving machine.

```
