Search code examples
gitgit-mergegit-bare

Do I need to merge a branch in a bare repo?


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?


Solution

  • 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.