How to Fork my own Repo on Github?
Here’s what I did, please adjust and change according based on your context
1. Create a New Repo On Github
Now, you will see a few boxes with …
Quick setup — if you’ve done this kind of thing before
or
[HTTPS] [SSH] [https://github.com/profoundhub/mean-stack-demo-fork.git]
We recommend every repository include a README, LICENSE, and .gitignore.
…or create a new repository on the command line
echo “# mean-stack-demo-fork” >> README.md
git init
git add README.md
git commit -m “first commit”
git remote add origin https://github.com/profoundhub/mean-stack-demo-fork.git
git push -u origin master
…or push an existing repository from the command line
git remote add origin https://github.com/profoundhub/mean-stack-demo-fork.git
git push -u origin master
…or import code from another repository
You can initialize this repository with code from a Subversion, Mercurial, or TFS project.
Don’t follow those steps, go to step #2 (below)
2. Clone the New Repo Locally
git clone https://github.com/profoundhub/mean-stack-demo-fork.git
What I saw:
$ git clone https://github.com/profoundhub/mean-stack-demo-fork.git
Cloning into 'mean-stack-demo-fork'...
warning: You appear to have cloned an empty repository.
Don’t panic, that’s normal
3. Add an Upstream Remote
cd fork-repo
git remote add upstream https://github.com/profoundhub/mean-stack-demo.git
4. Pull From the Original Repo
git pull upstream master
What I saw:
$ git pull upstream master
remote: Counting objects: 719, done.
remote: Compressing objects: 100% (241/241), done.
remote: Total 719 (delta 548), reused 625 (delta 464), pack-reused 0
Receiving objects: 100% (719/719), 215.50 KiB | 0 bytes/s, done.
Resolving deltas: 100% (548/548), done.
From https://github.com/profoundhub/mean-stack-demo
* branch master -> FETCH_HEAD
* [new branch] master -> upstream/master
That should do it!
Update:
If you …
$ git remote
You might see something like this:
origin
upstream
or
$ git remote -v
You might see something like this:
origin https://github.com/profoundhub/mean-stack-demo-fork.git (fetch)
origin https://github.com/profoundhub/mean-stack-demo-fork.git (push)
upstream https://github.com/profoundhub/mean-stack-demo.git (fetch)
upstream https://github.com/profoundhub/mean-stack-demo.git (push)
when I:
$ git status
I saw this:
On branch master
Your branch is based on 'origin/master', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
nothing to commit, working tree clean
So you have to do this for fix it:
$ git branch --unset-upstream
But I did not, instead …
In my case:
$ git remote add upstream https://github.com/profoundhub/mean-stack-demo.git
but got this error:
fatal: remote upstream already exists.
So I tried:
git fetch upstream
… and saw this:
From https://github.com/profoundhub/mean-stack-demo
* [new branch] Daniel -> upstream/Daniel
So I did this next:
$ git branch --unset-upstream
Then, to double check:
$ git status
On branch master
nothing to commit, working tree clean
Then, to triple check:
$ git remote
I saw this:
origin
upstream
And:
$ git remote -v
I saw this:
origin https://github.com/profoundhub/mean-stack-demo-fork.git (fetch)
origin https://github.com/profoundhub/mean-stack-demo-fork.git (push)
upstream https://github.com/profoundhub/mean-stack-demo.git (fetch)
upstream https://github.com/profoundhub/mean-stack-demo.git (push)
Finally, when I:
$ git status
No Return / No Errors
Naturally, of course I tried to push:
$ git push -u origin master
… I had to do some magic to get everything updated and pulled successfully:
https://github.com/profoundhub/mean-stack-demo-fork/pull/1
The best thing is now, I have more options:
via “Compare changes” (https://github.com/profoundhub/mean-stack-demo-fork/compare)
Compare changes across branches, commits, tags, and more below. If you need to, you can also .
Thanks,
That’s all folks!
PS: Remember that you may have to keep updating your fork from original repo to keep up with their changes, use this:
$ git pull upstream master