Git

Git “Cannot Publish Unborn Head” Error

When you are just getting started with Git, you will probably come across the “cannot publish unborn head” error. This can be annoying especially as a newbie as you are not familiar with the cause and source of this error.

In this tutorial, we will attempt to explain why this error occurs and how you can fix it when working with a Git repository.

What Does It Mean?

This error occurs when you attempt to push the changes to a Git repository but the version control system cannot find any commits to use as the starting point.

A common cause is when you are attempting to push the changes to a Git branch that does not have any commit.

This is because it needs a reference point which occurs as a result of commits into a Git repository.

How to Resolve It

Fixing this error is pretty straightforward. All you need to do is create a new file in your repository and add a new commit.

You need to do this on the local branch before attempting to push it into the remote repository.

You can do this using the “git add” command:

git add <file1> <file2> ...

This should add the specified files into the repo. To add all the files in the repository, you can add “all” as follows:

$ git add .

Once you are done, proceed to create a new commit as the reference point.

git commit -m "initial commit"

This should create a new commit with the specified commit message which acts the reference point in which Git starts to track your changes.

Push the Changes to a Remote Branch

Once we created the commit, we can proceed to push the changes into the remote branch using the “git push” command:

$ git push <remote-name> <branch-name>

Replace the “remote-name” and “branch-name” with your target details.

Conclusion

In this post, we covered the main cause of the “git cannot publish unborn head” error and how you can resolve it.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list