No Tracking Information Error in Git

Aren’t you following the right way to git? Are you frustrated with the message “There is no tracking information for the current branch”? Keep calm and read on.

The Problem

I create new Git repositories all the time - just like any other developer. I am too stupid to notice the small things and learn my lessons - unlike any other developer.

Often I mix up creating repositories on the GitHub website and in local computer, thereby confusing Git. I happily create a repository with a README, add remote URL, try to do a pull..

git pull origin master

.. and, what do I get? Lo and behold..

    From https://github.com/techformist/super_hero_project
    * branch            master     -> FETCH_HEAD
    fatal: refusing to merge unrelated histories

The solution is simple, but before that - let’s see the normal flow.

The Normal and Abnormal Flows for a New Project

  1. Create repository on GitHub site, or using GitHub Desktop
  2. Add files like README or license, or don’t
  3. Follow the helpful instructions to get the repository setup in local computer

    git init
    git remote add origin https://github.com/techformist/super_hero_project
    git push -u origin master
    

Simple.

Apparently I can’t follow instructions.

So, I do -

  1. Create project locally. Add a few useless programs, scripts and files
  2. Do a git init
  3. Create a repository on GitHub a few days later
  4. Add a README, license directly on GitHub. Because, why not
  5. Add remote to local and try to sync git pull origin master

Of course, there’s an error. Git sees changes on server and changes on local. It cannot just pull server to local.

Almost all the time, I revert to the below simple remedy.

git pull origin master --allow-unrelated-histories

This allows Git to pull stuff from server while retaining the local files. I can add them local files to the master branch and continue like nothing’s wrong with the world.

Another way to avoid the error is to create an empty repository on GitHub and avoid creating any files at the very beginning. Push local changes / sync, and from then on you can create files anywhere without antagonising Git.

Last updated:
Categories: Tools
Tags: tools
comments powered by Disqus