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:
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.
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.
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With