How to Upload your Repo to GitHub

What is GitHub? The first question is what is git? Git is a decentralized version control system created by Linus Torvalds that is used by a number of open source projects, most notably perhaps the Linux kernel. GitHub is a new hosted Git repository service that's being called a "social network" for programmers and with good reason. It also already has some high profile projects of its own on board: Ruby on Rails, Capistrano, Merb, Prototype and Scriptaculous, among others.

GitHub

I have been asked how do you upload to github. Keep in mind these are repos that you are uploading. There is no direct uploading that I am aware of. The best was is to use 3rd party packages like GIT which will allow you to upload your code from shell.

Once you login to github and create your repo, you will see the following instructions:

Create a new repository on the command line

touch README.md 
git init 
git add . 
git commit -m "first commit" 
git remote add origin git@github.com:linuxterminal/repotest.git 
git push -u origin master

Push an existing repository from the command line

git remote add origin git@github.com:linuxterminal/repotest.git 
git push -u origin master

Once you have the information above from github, then you are ready to get started with uploading to github. Install GIT from there downloads here. To install you can use the following:

Debian/Ubuntu

$ apt-get install git-core

RedHat/Fedora

$ yum install git

Gentoo

$ emerge --ask --verbose dev-vcs/git

Arch Linux

$ pacman -S git

FreeBSD

$ cd /usr/ports/devel/git
$ make install

Solaris 11 Express

$ pkg install developer/versioning/git

OpenBSD

$ pkg_add git

Please see image below for example:

 

Once you have this installed, you can now run "git" commands with shell. From here you will want to create your repo directory. I placed mine in '/home/user/Documents/GitHub/repotest'. Here you can add your repo files. For an example I added README.md and echo'd the following:

test-repo
=====
 
Installation
-------------
 
This is just a test repo. Description on how to upload to GitHub from Linux.
 
Extra
------------
 
Ubuntu Linux to Github

Once you have your README.md file created, you can then run the commands provided when you created your repo. Before hand you will want to setup your global config for github. Use the following commands to setup your username and email address:

#Setup your name with GitHub
 
git config --global user.name "Your Name"
 
#Setup your email address with GitHub
 
git config --global user.email "your@emailaddress.com"

At this point you may need to setup a SSH Key between your local box and GitHub. You can add your SSH Key once generate to GitHub here. At this point you can run the commands provided to you after creating your repo.

touch README.md
 
git init
 
git add README.md
 
git commit -m "first commit"
 
git remote add origin git@github.com:linuxterminal/repotest.git
 
git push -u origin master

View example below:

 

Few recommendations for this. When you go to "git add README.md," you can run "git add ." so git will fetch all files within that directory. Also you may run into issue with pushing if you are the root user. Run as non-root should work as normal. 

If all goes well, you should see the following in order:

user@ubuntu:~/Documents/GitHub/repotest$ touch README.md
 
user@ubuntu:~/Documents/GitHub/repotest$ git init
 
user@ubuntu:~/Documents/GitHub/repotest$ git commit -m "first commit"
 
user@ubuntu:~/Documents/GitHub/repotest$ git remote add origin git@github.com:linuxterminal/repotest.git
 
user@ubuntu:~/Documents/GitHub/repotest$ git push -u origin master
 
Counting objects 3, done.
 
Compressing objects (2/2), done.
 
Writing objects: 100% (3/3), 328bytes, done.
 
Total 3 (delta 0), reused 0 (delta 0)
 
To git@github.com:linuxterminal/repotest.git
 
*      [new branch]          master -> master
 
user@ubuntu:~/Documents/GitHub/repotest$

Then you should be able to see your file(s) on GitHub. Example image below:

 

If you have any questions, please feel free to comment below. The steps can get a little confusing but this tutorial should assist with that. Thanks.

Printed from: http://linuxterminal.org/how-to-upload-your-repo-to-github/ .
© Jeff Rangel 2013.

2 Comments   »

  • John N says:

    Thanks for the great article, worked like a charm. Viewed other articles and non were as helpful as this. Thanks again!
    John-

    • root says:

      Thanks for the comment and feedback, glad I was able to simplify this for you.
      -LinuxTerminal

RSS feed for comments on this post , TrackBack URI

Leave a Reply

CommentLuv badge