3

I have a local repository that I've cloned from my remote repository (all on one machine). I wanted to make sure that my remote repository picked the changes from my local repository so I did a git push origin.

I changed my working directory to my remote repository; the change had propagated to the log file (i.e. doing git log showed the change) but my actual working directory didn't show the change. I did a git checkout HEAD but the CWD still didn't change. It wasn't until I did a git checkout --force HEAD that the CWD synced up.

I suspect this is happening because the remote repository isn't a bare repository. So two questions:

  1. Is there a way that I can make the remote repository automatically sync (i.e. discard local changes) on a git push?
  2. Why do I need to to use --force to get it to sync up? What should be the process of syncing it up?
Avery
  • 10,391
  • 15
  • 38
  • 53

1 Answers1

2

If your push (to a non-bare) repo succeeded, it is because:

  • either you pushed a branch which wasn't checked out on your remote repo (the non-bare remote repo)
  • or receive.denyCurrentBranch was set to false or ignore in the git config

In the latter case, any current local modification wouldn't be erased by that push.
Only a git checkout --force would reset the working directory to the actual index content referenced by HEAD.

The usual way to ensure synchronization between two non-bare repo is by adding an intermediate bare repo (to which you push) with a post-receive hook which will go the actual remote repo (the non-bare one) and pull from the updated bare repo.
The usual example: Using Git to manage a web site, which I use in:

When you are pulling, make sure to unset GIT_DIR: see "Calling 'git pull' from a git post-update hook"

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283