How to create an empty branch for documentation
We have several Linux servers in the office. I would like to keep some record of changes in settings. Therefore I thought it would be a good idea to put all configuration files in GIT.
The setup I would like to have is as follows:
bare repository –> configuration.git
with a branch for every server in which we put the directory structure and the configuration files.
- Feature branch based on master (without checking out master)
- Why does git fast-forward merges by default?
- How to remove an in-between merge in git?
- Rename master branch for both local and remote Git repositories
- How can I stash some files and commit to a new branch the rest?
- Merge changed files from feature to a hotfix git flow
I can’t find how to do this. Somewhere I read something with –orphan but somehow I ended up with and master and MASTER branch and no empty branch for my configuration files.
I want an empty branch with no history and no link to the master.
Can anybody point me in the right direction?
3 Solutions collect form web for “How to create an empty branch for documentation”
Keep in mind an important passage from the documentation on
git checkout --orphan:
If you want to start a disconnected history that records a set of paths that is totally different from the one of , then you should clear the index and the working tree right after creating the orphan branch by running
git rm -rf .from the top level of the working tree. Afterwards you will be ready to prepare your new files, repopulating the working tree, by copying them from elsewhere, extracting a tarball, etc.
To start a new branch for server1, run
git checkout --orphan server1 git rm -rf .
From there, add and commit as usual, e.g.,
touch foo.conf git add foo.conf git commit -m 'Create foo.conf'
You have to do the following:
- Create your
server01create the branch
git symbolic-ref HEAD refs/heads/server01
rm -f .git/index
git clean -fdx
IMPORTANT: You must now add and commit something to this branch.
Repeat with 2. for the next server.
Afterwards you can simply do a
git checkout serverXX to change the branche.
If you didn’t have an initial commit in the
master branch then you will not have a
master branch after this procedure. (But you can just do what was described in 2. for the
You can check the result with
git log --graph --branches --decorate
It should look like this:
* commit: .... (server01) Author: Max Muster <email@example.com> Date: Mon Feb 2 16:00:00 2015 +0100 First commit of server01 branch * commit: .... (server02) Author: Max Muster <firstname.lastname@example.org> Date: Mon Feb 2 16:01:00 2015 +0100 First commit of server02 branch * commit: .... (server03) Author: Max Muster <email@example.com> Date: Mon Feb 2 16:03:00 2015 +0100 First commit of server03 branch [...] * commit: .... (HEAD, server99) Author: Max Muster <firstname.lastname@example.org> Date: Mon Feb 2 17:00:00 2015 +0100 First commit of server99 branch
If Git is telling you that you are still in the master branch, then it likely means that not only are you in the wrong branch, you are in the wrong repository. If I read your description correctly, you want a separate repo (and branch) for your server configuration files. Try the following steps:
- Change to the root directory containing your configuration files. Make sure that this directory is not contained within the repo of your master branch or any other already-existing git repo.
git init. This initializes your directory to be a Git repository
git add ... This adds all the configuration files in your directory to be tracked by Git. If you only want certain files you can add them with
git add [filename].
- You are now ready to start using Git. The default branch is master, but you can create any branch you want, and commit your changes.