September 21, 2016

Creating a new Github repository and link it to the local existing project in your computer

1. Create a new repository on GitHub

2. Get the remote repository Web URL by pressing the "Clone or Download" button (coloured green). It looks like this : https://github.com/iserifith/ScoreBoard.git

3. Open Terminal and go to your local project folder where you have the files you have been working on.

4. Initialize the local project folder as a Git repository using the following command :
git init

5. Add the files in the project folder into "local git repository" - this is called "staging".
git add .

Note : This does not connect to "remote git repository". Understand the difference between local and remote git repository.

6. Commit the files that you've staged in your local repository.
git commit -m "First commit"

7. Now we set so that our local repository are linked to the remote repository. This command set the remote repository as the "origin".
git remote add origin {remote repository Web URL}

Example : git remote add origin https://github.com/iserifith/ScoreBoard.git

8. Verify that our remote repository are linked properly using
git remote -v

It will prompt you something like this :
origin https://github.com/iserifith/ScoreBoard.git (fetch)
origin https://github.com/iserifith/ScoreBoard.git (push)

9. Once all set, push the all files (that we have committed just now) in your local repository to GitHub using the following command :
git push origin master



Extra :
Now, to make sure you keep updated Github with your work, all you need to are 3 steps :

1. Add all files (staging)
git add .

2. Commit
git commit -m "I did some changes"

3. Push to Github (remote repository)
git push origin master