DEV Community

Cover image for "fatal:" doesn't have to be fatal.
Andrew Jackson
Andrew Jackson

Posted on

"fatal:" doesn't have to be fatal.

The Beginning

I have been working on becoming a Systems Engineering Virtual Intern at OLE for the past 2 and a half weeks. It has been pretty cool talking with the people on the project and helping an open-sourced project such as treehouses. I am hoping that having something like this on my resume would help me get that first job finally but, it is also a way for me to learn more. You get to use GitHub in a professional setting and in that you have to be more careful than you already were.

But, when you see something like this:

Andrews-MacBook-Pro:sonAndrew.github.io sunnyredd$ git fetch upstream
fatal: 'upstream' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

You start to freak out. Oh nooooo! What did I do! What did I do!

In this example, I am attempting to make sure my master branch is up to date with the upstream master branch. As you can see something went wrong. I got a "fatal:" warning that says my upstream didn't exist and to make sure I have the correct access. This freaked me out and made me question my sanity.

Am I actually working on this project?
Is this project even real?
Am I real???

After I snapped out of it I started searching the web (as you should) to find help with this problem. I copied the warning and placed it directly into google(for the best results) and found a few pages that helped. The first was on StackOverflow. I tried the suggestions that were mentioned on this page and still had this problem where I could not get the data I wanted. I was only trying to make sure my branch was up to date and it turned into a fatal nightmare.

I then push on to the next page which was a link on that StackOverflow post to Github that suggested I add a new upstream. I then proceeded to delete the current upstream through git remote rm upstream and then re-added the upstream. I tried git fetch upstream again to no avail my current branch is still not up to date. What do I do now?

If you are like me and have gotten this error don't be frightened. I'm pretty sure this could have happened to anyone if they were not paying attention...

"fatal:" doesn't have to be fatal.

To combat this "fatal:" warning you can do a couple of things. I'm not sure if the second one is good practice but none the less here they are.

First is probably the best (this is also a restart of adding upstream to local) try:

To remove upstream

1 git remote -v - Copy upstream URL
2 git remote rm upstream - This removes upstream URL

To add upstream

3 git remote add upstream <upstream-master-url> - Adds upstream URL
4 git remote -v - To make sure you have the right URL

To sync local with upstream

5 git fetch upstream - Fetch branches from the upstream repository
6 git checkout master - Checkout the master branch
7 git show-branch - See branches and the changes made in them
8 git merge upstream/master - Repo should now be synced to upstream/master

To compare local changes

9 git diff - for comparing different versions of the same file
10 git status - to view the changes made in the branch, whether the branch is up-to-date with master

To update local

11 git pull - to sync the local repository with the remote repository
12 git push - to push the updates that you made to the local repositories to the GitHub repositories

Yes, you probably forgot to merge after you fetched the first time but that's ok this is a learning experience. I know all this other stuff was extra but it is a good practice when working on a team that you start from #5 before beginning to work that way you don't have conflicts.

So I hope this helped you in you and now you may have a reference to look back on when you get this error again... Lol just playing... Maybe...

Oh! and here is the second one.

Second is probably not the best but if you get this error as well: Error: Permission denied (publickey) it may help try:

git reset --hard <commit-hash>
git push --force origin master

The would be the current branch HEAD you would like to commit to. You would find this by going to the upstream repo and clicking commits and you would find the hash on the right side. With this, you have to make sure the commit is stable/varified or you will be in the same boat again(don't ask how I know). If you chose an older commit to start with, you can start on #5 afterward.

Well hopefully this helped and thanks for reading.

Discussion (0)