owned this note
owned this note
Published
Linked with GitHub
# Understanding Github better
### What is the difference between forking and cloning?
When you fork a repository, you create a copy of a github repository on your github account.
When you clone a repository, you create a clone of the repository locally - on your computer.

<b>Consequences: </b>
- If you have forked AND cloned a repository, you will be able to push your changes on your github copy but not on the original. Similarly, you won't be able to pull the changes from the original if there are any (at least not with a simple "git pull")
- If you have cloned a github repository without forking it first, and that you have been authorized, you will be able to push changes to that github repository, and pull from it.
### How can I create a repository on github?
Depending on the context, there are several ways to do this.
<ol>
<li>Fork an existing repo on github, then clone it on my computer. No need to initialize it with "git init" in this case. </li>
<li>Create an empty new repo on github, then clone it on my computer. No need to initialize it with "git init" in this case.</li>
<li>Create an empty new repo on github. Independently, create a folder on my computer. Initialize the local folder. Connect the two.</li>
</ol>
### Once my repo is created, how can I work with others on github?
If you want to work with collaborators, you all need to work on the same github repo.

In order to achieve this, one person can invite the others on the repo, and they will clone it on their computers.
Then, you will work on your own computer, and you will want to:
1. Update your local version with the changes made by your collaborators (<b>pull</b>)
2. Update the github repo with your changes (<b>push</b>)
However, you can't just git pull and git push whenever you want! Github needs everything to be up to date before.
When you want to pull, if you have made some changes on your side, this is what you should do:
- git add
- git commit
- git pull
When you want to push, this is what you should do:
- git add
- git commit
- git pull
- git push
<i>Please note that I am using 'git pull' and the others as abbreviations - you need to specify what you are adding, commenting and pushing when you actually use them.</i>
If you have worked on the same files as your collaborators, there may be 👻 merge conflicts 👻! Spooky.
Don't worry though, it's perfectly normal! Github will present to you the 2 versions (the local one - <em>current change</em>, and your collaborators' one - <em>incoming change</em>). You will have the opportunity to accept one of them, or both.
### Test your understanding with this [quiz](http://www.quiz-maker.com/QK52VPNR4)!