Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between "git symbolic-ref HEAD refs/heads/gh-pages" and "git branch gh-pages"?

Tags:

git

github

This is the process given to create a branch for GitHub Project Pages:

cd /path/to/repo-name
git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
echo "My GitHub Page" > index.html
git add .
git commit -a -m "First pages commit"
git push origin gh-pages

It states that git symbolic-ref HEAD refs/heads/gh-pages will create a new root branch. I'm wondering what the difference between a root branch and a regular branch is.

like image 729
James Chevalier Avatar asked Jan 31 '12 23:01

James Chevalier


People also ask

What is git symbolic ref?

A symbolic ref is a regular file that stores a string that begins with ref: refs/ . For example, your . git/HEAD is a regular file whose contents is ref: refs/heads/master .

What is GH page branch?

git checkout gh-pages means you've switched to the branch named 'gh-pages'. Any change you commit to this branch is picked up by github to build your github pages. To switch back to the 'master' branch (presumably your source code), do git checkout master .

What is ref and head in git?

git/refs/ . In Git, a head is a ref that points to the tip (latest commit) of a branch. You can view your repository's heads in the path . git/refs/heads/ . In this path you will find one file for each branch, and the content in each file will be the commit ID of the tip (most recent commit) of that branch.

What is git head branch?

When working with Git, only one branch can be checked out at a time - and this is what's called the "HEAD" branch. Often, this is also referred to as the "active" or "current" branch. Git makes note of this current branch in a file located inside the Git repository, in . git/HEAD .


1 Answers

A "root branch" is one without a previous history. *

If you are at master and you do git branch gh-pages, gh-pages will be basedd off master.

Here, the intention is to create a branch for github pages, which is typically not associated with the history of your repo (master and other branches) and hence the usage of git symbolic-ref

Also see here: https://stackoverflow.com/a/8815361/526535

* It is also called an orphan branch and git checkout --orphan will now do the same thing as the git symbolic-ref that was being done before

Also see my answer here: https://stackoverflow.com/a/5690048/526535

like image 129
manojlds Avatar answered Oct 01 '22 20:10

manojlds