Git: Origin vs Upstream

Upstream mostly refers to the original repo that you have forked.

Origin refers to the forked repository. Most often this is the repository that you cloned. (assuming that you forked the upstream and clone the forked repository instead of cloning directly the upstream)

When a repo is cloned, it has a default remote called origin that points to your fork on GitHub, not the original repo it was forked from.
To keep track of the original repo, you need to add another remote named upstream

so when we do git pull or git push then by default it will go to origin.

Git – How to deal with “Refusing to merge unrelated histories”

Sometimes when I do “git pull” I got a message back 

fatal: refusing to merge unrelated histories

After some searching, I found the solution is to force the pull to allow unrelated histories by using this command

git pull --allow-unrelated-histories

I still don’t know yet what the reason behind it. But I will surely try to find it out and when I find the reason behind it, I shall share it here as well. 

Git – Rewrite History

There was time that you accidentally commit code to repository that you are not supposed to commit such as your password, or any secret code. I was looking for a way to revert the committed code that I have pushed in my repository. 

In git you can do it by rewriting the history. Below is how you can rewrite your history.

git rebase -i HEAD~3

HEAD~n : the n is the index of commit you want to rewrite from the HEAD. With the command above, it will give you the list of commits from the HEAD until the index 3. With this list you can choose between squash, drop, pick, etc.

After you rewrite the history then you can continue with 

git commit --amend
git rebase --continue

you can repeat these steps for each commit you change.