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
- Create repository on GitHub site, or using GitHub Desktop
- Add files like README or license, or don’t
- 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 -
- Create project locally. Add a few useless programs, scripts and files
- Do a
git init
- Create a repository on GitHub a few days later
- Add a README, license directly on GitHub. Because, why not
- 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.