{"id":99,"date":"2013-02-15T22:44:59","date_gmt":"2013-02-15T22:44:59","guid":{"rendered":"http:\/\/digital-madness.in\/blog\/?p=99"},"modified":"2018-02-17T18:01:04","modified_gmt":"2018-02-17T18:01:04","slug":"github-for-beginners-debianubuntulinux","status":"publish","type":"post","link":"http:\/\/digital-madness.in\/blog\/2013\/github-for-beginners-debianubuntulinux\/","title":{"rendered":"GitHub for beginners (debian\/ubuntu\/linux)"},"content":{"rendered":"<p>Just\u00a0yesterday I was trying to setup my first github repository, but it wasn&#8217;t that easy I thought it would be. YES I know, github has a support page, but \u00a0it didn&#8217;t seemed to work for me.<\/p><p>So here, I&#8217;ll give you a little introduction on the initial setup of git on your local machine and setting up of your cloud repository on github. This tutorial is for debian\/ubuntu users.<\/p><p><strong><span style=\"text-decoration: underline;\">GIT<\/span><br \/>\n<\/strong>Git is an extremely fast, efficient, distributed version control system ideal for the collaborative development of software.<\/p><p><span style=\"text-decoration: underline;\"><strong>GITHUB<br \/>\n<\/strong><\/span>GitHub is the best way to collaborate with others. Fork, send pull requests and manage all your\u00a0public\u00a0and private\u00a0git repositories. In simple terms, it is a cloud storage for all your repositories, be it local or distributed.<strong><br \/>\n<\/strong><\/p><p><span style=\"text-decoration: underline;\"><strong>SETTING UP OF GIT REPOSITORY ON LOCA<\/strong><strong>L<\/strong><\/span><strong><span style=\"text-decoration: underline;\"> MACHINE<\/span><br \/>\n<span style=\"color: #ff0000;\">NOTE:<\/span> GIT CAN BE USED WITH\/WITHOUT GITHUB. GIT is a subversion control system which can just be used solely on your local machine without using github at all.<\/strong><\/p><p>First we&#8217;ll setup git on the local machine and create a local repository.<br \/>\nInstall GIT using the command on your terminal:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo apt-get install git<\/pre><p>This will install git on your machine. Now you we\u2019ll start by doing a bit of configuration. Every commit you make will have your name and email address to identify the \u2018owner\u2019 of the commit, so you should start by giving it those values. To do so, run these commands:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">git config --global user.name \"your name\"\r\ngit config --global user.email \"your@email.com\"<\/pre><p>So Git knows who you are now. Let&#8217;s work upon the local repository we were talking about,\u00a0\u00a0just imagine you are\u00a0creating a simple PHP web app. (Of course, the bigger the project, the brighter Git shines, but we\u2019re just learning the tools, right?)\u00a0We&#8217;ve\u00a0got an empty directory called \u2018project\u2019. Add all your project files in the new created empty directory. This is the base directory for your repository. To get started with your very own repository, first change your current working directory to the base repository directory and initialize git. Type:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">cd \/path\/to\/project\/\r\ntouch README.md\r\ngit init\r\ngit add *\r\ngit commit -m \"commit message\"\r\ngit status<\/pre><p>Let me explain each command I typed:<\/p>\n<ul>\n<li>cd \/path\/to\/project\/: This just changes your current working directory to the project directory for setting up of repository.<\/li>\n<li>touch README.md: README.md is a file used by github as a default readme file. So we create an empty file. This step is not necessary, but it surely makes you ready for uploading your repository on github.<\/li>\n<li>git init: this initializes your git repository by making a &#8220;.git&#8221; directory as a sub-directory to your project directory. This is the magic black box used by git where all the different branches, logs and commits are kept.<\/li>\n<li>git add *: This adds all the files to be committed to a staging area.\u00a0The staging area is a spot to hold files for your next commit; maybe you don\u2019t want to commit all your current changes, so you put some in the staging area. &#8220;*&#8221; is used to add all the files. You can be specific in adding files. Just use &#8216;*.js&#8217; to only add javascript files.<br \/>\nyou can remove files from the staging area and subsequently from your commit using the command: git rm file_name<\/li>\n<li>git commit -m &#8220;commit message&#8221;: It finally commits the staged files and logs the given commit message for you to recognize your commit later on when you want to rollback or branch.<br \/>\nFor skipping the staging area and updating all the <strong>already<\/strong> committed files use:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">git commit -am \"commit updated\"<\/pre>\n<\/li>\n<li>git status:\u00a0The\u00a0<em>git status<\/em>\u00a0command allows you to see the current state of your code.\u00a0We&#8217;ve\u00a0just done a commit, so\u00a0<em>git status<\/em>\u00a0will show us that there\u2019s nothing new.\u00a0If you continue working on your imaginary project, you\u2019ll see that the status changes. If you have any new files, it will show you the files under &#8220;untracked files.&#8221; or if you have made changes to the files already committed, it will show you the files under &#8220;changed but not updated&#8221;. Again running the add and commit commands will add these new\/changed files to a new commit.<\/li>\n<\/ul><p>You can checkout all the available commands\/features on git here:\u00a0<a href=\"http:\/\/git-scm.com\/book\/commands\">http:\/\/git-scm.com\/book\/commands<\/a><\/p><p>you can similarly setup more repositories on your local machine. \ud83d\ude42<\/p><p><span style=\"text-decoration: underline;\"><strong>SETTING UP GITHUB REPOSITORY<\/strong><\/span><\/p><p>Git is a great way to share code with others and work on projects together. There are a number of Git repository hosting sites. We\u2019ll just look at one.<br \/>\nFirst I expect you to make an account on GitHub here:\u00a0<a href=\"https:\/\/github.com\/\">https:\/\/github.com\/<\/a><\/p><p>When you&#8217;re done with it, create a cloud repository. Instructions are given here:\u00a0<a href=\"https:\/\/help.github.com\/articles\/creating-a-new-repository\">https:\/\/help.github.com\/articles\/creating-a-new-repository<\/a><\/p><p>So when your&#8217;re done with all this, you can go further and start committing your code on the cloud. For committing your code online, you will need a SSH public key,\u00a0so let\u2019s create that right now! Open your terminal and type:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">cd ~\r\nssh-keygen -t rsa -C \"your@email.com\"<\/pre><p>This creates a SSH public key to be used in connecting to GitHub.\u00a0The t option assigns a type, and the C option adds a comment, traditionally your email address. You\u2019ll then be asked where to save the key; just hitting enter will do (that saves the file to the default location). Then, just hit enter again twice when it asks you for a pass-phrase (pass-phrase is just a headache. If you type one, you will have to type one everytime you connect to github).<\/p><p>The key is stored in the default directory which is ~\/.ssh\/<br \/>\nCopy the contents of the public key. Here&#8217;s how you can do it from the terminal:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo apt-get install xclip\r\n\r\ncd ~\/.ssh\/\r\ncat id_rsa.pub | xclip<\/pre><p>This copies the content of your public key to your clipboard. If you directly copy it using a text editor, remember\u00a0not to add any newlines or white-space.<br \/>\nNow go to your GitHub account. Go to account settings. Click on SSH keys tab and finally click on add SSH key. Copy the contents of the clipboard in the key section. You can give any title you want. Now try connecting to the github server using SSH. Just type in your terminal:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">ssh -vT git@github.com<\/pre><p>You should be able to connect to the github server. If not, and getting an <strong>agent forwarding error\u00a0<\/strong>you may have to unset SSH_AUTH_SOCK. You can read more about ssh and public keys and agent forwarding here:<br \/>\n<a href=\"http:\/\/www.unixwiz.net\/techtips\/openssh.html\">http:\/\/www.unixwiz.net\/techtips\/openssh.html<br \/>\n<\/a><a href=\"http:\/\/www.unixwiz.net\/techtips\/ssh-agent-forwarding.html\">http:\/\/www.unixwiz.net\/techtips\/ssh-agent-forwarding.html<\/a><\/p><p>To unset the environment variable:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">unset SSH_AUTH_SOCK<\/pre><p>Try and connect to the github server once again. If still not able to connect, use the github help:\u00a0<a href=\"https:\/\/help.github.com\/articles\/\">https:\/\/help.github.com\/articles\/<\/a><\/p><p>Once you are able to contact the github server, you can start uploading your commits to your cloud repository. Here&#8217;s how you can do that:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">cd \/path\/to\/project\/\r\ngit remote add origin git@github.com:username\/cloud_repository_name.git\r\ngit push origin master<\/pre><p>This pushes the master branch to the origin remote. Now you\u2019re project is available to the world! Head back to your project page and see your project. If you are getting an error in uploading the, again try connecting to the github server using ssh and debug the connection.<\/p><p>You might be on the other end of a project: you\u2019re a contributor instead of the owner. When the owner pushes a new commit to the repository, you can use\u00a0<em>git pull<\/em>\u00a0to get the updates.\u00a0<em>Git pull<\/em>\u00a0is actually a combo tool: it runs\u00a0<em>git fetch<\/em>\u00a0(getting the changes) and\u00a0<em>git merge<\/em>\u00a0(merging them with your current copy).<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">git pull<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Just\u00a0yesterday I was trying to setup my first github repository, but it wasn&#8217;t that easy I thought it would be. YES I know, github has a support page, but \u00a0it didn&#8217;t seemed to work for me.So here, I&#8217;ll give you a little introduction on the initial setup of git on your local machine and setting&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"","footnotes":""},"categories":[42],"tags":[26,27,28,25,24],"class_list":["post-99","post","type-post","status-publish","format-standard","hentry","category-github","tag-git","tag-github","tag-repository","tag-svn","tag-version-control"],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/posts\/99","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/comments?post=99"}],"version-history":[{"count":9,"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":198,"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/posts\/99\/revisions\/198"}],"wp:attachment":[{"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/media?parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/categories?post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/digital-madness.in\/blog\/wp-json\/wp\/v2\/tags?post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}