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:
This should add the specified files into the repo. To add all the files in the repository, you can add “all” as follows:
Once you are done, proceed to create a new commit as the reference point.
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:
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.