Reb.Cabin
Reb.Cabin

Reputation: 5567

Surprised by git remote behavior

On mac OS-X Mavericks, trying to make a local clone of a repo origined on a mounted volume.

I create the origin repository

pushd /Volumes/somevolume
mkdir testbox
cd testbox
git init

I put, add and commit a file in it

cat > test.text
testing git remote
^D
git add -A
git commit -am "initial commit"

I now clone the repo to my regular home

pushd ~/Documents
git clone /Volumes/somevolume/testbox
cd testbox
cat test.text

Everything is OK. Now I change and commit the file, here in my local clone

cat >> test.text
a new line
^D
git commit -am "add a new line to test.text"

check that it's really changed

cat test.text
testing git remote
a new line

and push it to the remote origin

git push origin master

EDIT: I get a warning that I don't understand

Counting objects: 5, done.
Writing objects: 100% (3/3), 277 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: warning: updating the current branch
To /Volumes/lockbox/testbox/
   bb6f7d1..5d2f521  master -> master

I now go check that the file got pushed

pushd /Volumes/somevolume/testbox
git status

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   test.text
#

well that's weird... let's see if the file contains what I thought I pushed...

cat test.text
testing git remote

the new line I tried to add and push isn't here, even though git thinks the file is modified? And why should I have to do anything in the origin remote after pushing from the local working directory? Github doesn't seem to work that way. Maybe the changes are here somewhere

git diff

No changes visible. I am now TOTALLY confused.

Upvotes: 1

Views: 52

Answers (1)

larsks
larsks

Reputation: 311298

When you push to a non-bare remote repository, your changes are recorded to the repository in the .git directory but are not applied to the checked-out version of the repository (the "working copy"). This is why it is generally recommended to only use bare repositories as remotes, because otherwise the behavior can be confusing.

You'll note that after pushing, your original repository showed that the file test.txt was modified:

pushd /Volumes/somevolume/testbox
git status

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   test.text

This is because the file now differs from the contents of the repository.

The warning "remote: warning: updating the current branch" is alerting you that you're pushing to a branch that is currently checked out.

There are times when you may actually want to push to a non-bare repository (maybe you're deploying a website with git push or something), but you need to set up an appropriate mechanism for applying updates to the working copy (and you generally need to treat the working copy as read-only in order to avoid conflicts).

Upvotes: 1

Related Questions