Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git merging branches in a bare repository

I would like to create the following setup for my git repos:

I currently have a local git repo with all my working files. I would like to be able to setup a central bare repository, and two other non-bare repositories -- one for a live application and one for a testing version.

I would like to be able to push changes from local to the central bare repo on a testing branch. Then, on my testing repo, always pull from the testing branch of the bare repository.

When ready to go live with the changes, I would like to be able to merge my testing branch and my master branch in the central bare repository. Then the live repo could pull from the master branch.

So in this scheme, testing repo will always pull from testing branch, and live repo will always pull from the master branch.

I can't figure out how to merge branches in a bare repository though. git-merge and git-checkout don't seem to work without the working tree.

So, my question is two-fold:

  1. Is there a standard way to merge branches in a bare repo?
  2. Is this not straight-forward because the setup of my repos is poor? (In which case, how would you modify this architecture for best practices?)
like image 619
user480029 Avatar asked Nov 02 '11 17:11

user480029


People also ask

Can I merge branches locally?

To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.

Can you merge multiple branches in git?

Git merge is a powerful command that will allow you and your team to use different branches to work on new features, and then bring them together to your main repository.

How does Git merge work with remote branches?

Instead, Git performs a three-way (or recursive) merge commit. If you create a branch in your local repository, the remote repository is not aware of the branch’s existence. Before you can push the branch code in the remote repository, you set the remote repository as the upstream branch using the git push command.

Why doesn't Git merge work in a bare repository?

And git merge and most other commands don’t work, because there is no HEAD inside of a bare repository. To answer your question: You don’t work within the bare repository. A bare repository is only there to keep the data; if you want to work with it, use a clone which is not bare.

How do I create a branch in the bare repository?

Usually you don't create branches directly in the bare repository, but you push branches from one work repository to the bare. git push origin myBranch.

Can I create a branch from a previous commit in Git?

You can create a branch from a previous commit on an existing branch. Remember, a commit is just a snapshot in time of the files in a repository. You create a branch from a commit if you want to work on a specific snapshot of the files. Before creating the branch, you need the SHA-1 identifier of the commit.


1 Answers

Note, this can actually be done on a bare repo, but you have to work around the normal interface.

$ git read-tree -i -m branch1 branch2
$ COMMIT=$(git commit-tree $(git write-tree) -p branch1 -p branch2 < commit message)
$ git update-ref mergedbranch $COMMIT
like image 87
kleptog Avatar answered Sep 27 '22 19:09

kleptog