2

In my setup I have three repos:

  1. A bare repo on remote server (/op/git/proj.git)
  2. A non-bare repo on remote server (/var/www/proj/.git)
  3. A non-bare repo on local machine (/var/www/proj/.git)

The bare repo is origin to both ordinary repos on local and remote.

Whenever I do a commit on local, I do a local push to bare repo and then pull on ordinary remote repo and I get my changes on remote.

Now, I want to merge branch A to master which method should I use? (Assume master is the current branch on both repos)

Method 1
1. local$ git merge A
2. local$ git push origin master
3. remote$ git pull origin master

Method 2
1. local$ git merge A
2. remote$ git merge A

I am not sure if the second method is all I need to do or not, in other words, since you cannot do things like checkout and merge in a bare repo, do you need to do anything to the bare repo after a merge?

Majid Fouladpour
  • 29,356
  • 21
  • 76
  • 127

1 Answers1

3

Use method 1.

Method 2 would only work if git merge A will be a fast-forward on both local and remote. If any of the git merge A operations result in a merge commit (not fast-forward), the master branches will have diverged.

In general, merging the same branch in multiple locations is rarely useful in practice.

do you need to do anything to the bare repo after a merge?

Just push to it, that's all.

janos
  • 120,954
  • 29
  • 226
  • 236
  • This is the right answer (and upvoted), I just want to add a comment that the full merge process uses both the index and the work-tree to store all the intermediate results. While a bare repository does have an index, the very definition of "bare repository" is "does not have a work-tree", so the reason you *can't* merge in a bare repository is that it is missing a critical element for the merge process. – torek Oct 29 '16 at 22:20