Create a Git Repository and Push it to Github

By | November 6, 2015

In this post, you will learn how to setup a local git repository in Linux and upload it to your Github account.

Github is like a social networking site for computer programmers. You can share your code with the world so that anyone can view it, copy it, and improve upon it.

Create your Github account

Open a Github account and create a Github repository, but do not add any files to it.

Follow the instructions below to upload code from your computer to Github.

Setup Git

You can configure Git with a few simple commands.

Install git:

sudo apt-get install git

Set your git username. This name will be including in your commits for identification purposes.

git config --global user.name "username"

An email is also required, but you can make it private.

git config --global user.email "username@users.noreply.github.com"

Use these commands to confirm your username and email:

git config --global user.name
git config --global user.email

Change into the directory where your code is and initialize the git repository. This command will create a hidden .git directory in your code directory.

git init

Find out which files in the project directory are being tracked by git. The files colored in red are not being tracked.

git status

Add a specific file to the git staging index. As per Github, all repositories should include a README.md and LICENSE file. For example:

git add spaceinv.asm
git add README.md
git add LICENSE

If you simply want to add everything within a directory to the git repository:

git add .

Check the status again to see that a commit is possible.

git status

Commit a file to the repository (this packages everything in the staging index and sends it to the repository).

git commit -m "First Commit"

Push Repository to Github

Now to push the repository to Github. First, configure a Github origin. When you do this, you will be asked for your Github username and password.

git remote add origin https://github.com/username/repository.git

Finally, push your repository to Github

git push -u origin master

You can now check your repository at github.com and verify that your commit was successful.

Github Video Series

The following is a great video series that explains what git is and how to use it:

Fork a Repository

https://help.github.com/articles/fork-a-repo/

Syncing a Fork

https://help.github.com/articles/syncing-a-fork/

Leave a Reply

Your email address will not be published. Required fields are marked *

*