Git 101 : Github Basics Pt1
Category : DevOps Tag : 101series shellscript
Nov. 28, 2020, 1:13 a.m.

Short Description :
Basic commands for git operations, such as add/commit to repo, change/merge branch etc.
source : datak

<h3 style="text-align: justify;">What is a git in a nutshell?</h3><p style="text-align: justify;">Git is a version control system for files you track. Git breaks down these files into each component and track versions as a snapshot of an image, and creating new image if there is any changes. These breakdown concept is used many places, such as docker build for CaaS (Container as a Service) and any cloud platform for PaaS (Platform as a Service). This runs at local laptop.</p><p><br></p><h3>What is a github and gitlab and how these are different with a git?</h3><p style="text-align: justify; ">Then what is github and how it's different with a git? Github is owned by github company and they use git as one of their services. Github makes git for a more people use, like group based development hosting repository server at web, which is called github repository. For example, if engineer A create new versions that he would like to official implement. He then update these versions to github either as one of branch version or official(master) version, and github notifies other engineers asking if these changes can be merged to official. There are other company/open source who has similar online git system, such as gitlab. Gitlab is known to use for customizable usage, company internal git applications, as an example.</p><p><br></p><h3>So how github is used?</h3><p style="text-align: justify;">Git is built into many of IDEs (Integrated Development Environment), but using CLI (Command Line Interface, like terminal) will give us more flexibility. For an installation and initial set up, there are many sites they explains and followings are few of references(<a href="https://docs.github.com/en/free-pro-team@latest/desktop/installing-and-configuring-github-desktop" target="_blank">github installation &amp; setup (github official)</a>, <a href="https://git-scm.com/" target="_blank">git installation</a>). We'll focus more on typical use cases post installation, using github.</p><p><br></p><h3>STEP1. Create new repository</h3><p>Couple of cases when we would like to create new remote repository at github.</p><ol><li>We already have local repository which has files</li><li>There is a reference files at web (like at github or gitlab)</li><li>We would like to create from scratch</li></ol><p>Either way first step is to have local folder(local repository) where you would would like to start git based version control, which will be a local repository. For #1 case,</p><pre>cd &lt;folder/repository name&gt;<br></pre><p>#3 case would need to create folder first then move the folder</p><pre>mkdir &lt;repository name&gt; cd &lt;repository&gt;</pre><p>Then initialize the folder</p><pre>git init</pre><p>In case of #2 (reference files at web), copy the url from the site</p><p><img src="/media/django-summernote/2020-12-03/8523adcf-0a95-4300-ac85-4c0e81acbb80.png" style="width: 100%;"><br></p><p>then,</p><pre>cd &lt;one higher level of directory where you would like to clone the repository&gt; git clone &lt;your copied url or ssh&gt; #repository folder will be automatically created</pre><p>Folder name(your cloned local repository) inherits remote repository name from copied site. We could keep using the folder name, but can change by</p><pre>mv -r &lt;your copied repository name&gt; &lt;your new local repository name&gt;</pre><p>This copied folder still connects to copied remote repository. For a group development and if copied remote repository is official repository, you could keep using the url. Meanwhile in case you would like to create your own url from the version of copied site, we need to overwrite remote repository. To check connectivity on which url is tied to,</p><pre>git remote -v</pre><p>and if we would like to overwrite,</p><pre>git init rm -rf .git</pre><p>to remove any git related information from the directory. Or, you can simply change remote repository and proceed to reset new remote repository following below</p><pre>git remote remove origin</pre><p><br></p><p>After that we would need to have a path to the local repository. Except for #2 and we would like to continue using the remote repository to make an update, we will create a new remote repository at github. Go to your page then going to "repositories" tab and push "New" button.</p><p><img src="/media/django-summernote/2020-12-03/12158bef-32fc-4b9d-acfb-fc4b6ed3d788.png" style="width: 1236px;"><br></p><p>Then type repository name and description. Repository name is better to specify the project so we could quickly understand what is the repository for. For a private use, you could choose "Private" in the radio button. We will leave readme.md and .gitignore as blank and we'll add later. Click "Create Repository"</p><p><img src="/media/django-summernote/2020-12-03/f8b90be8-28b7-45c2-8b82-9242304d9b3d.png" style="width: 100%;"><br></p><p>Then everything else is to follow the screen from the site.</p><p><img src="/media/django-summernote/2020-12-03/c9e294cc-01f0-470c-b6e4-cdebc79abbe4.png" style="width: 100%;"><br></p><p>To connect a path to your local repository,</p><pre>git remote add origin &lt;your github url&gt;</pre><p>You can check a path by</p><pre>git remote -v</pre><p>and you will see the url you would like to connect.</p><p><br></p><p>For an initial commit</p><pre>git add . # "." means everything in the directory. we could specify the file/folder if any. <pre>git commit -m '&lt;your initial commit message, such as "initial commit"&gt;'<br>git push origin master</pre></pre><p>You will see your local repository is now pushed to the site.</p><p><br></p><h3>STEP2. Update repository</h3><p>Now that you've done initial commitment and push to remote repository at github. You will have an update and next revision eventually and would like to push to github for a new revision. Step 2 include how to update new changes to remote repository.</p><p>Your will see current status by</p><pre>git status</pre><p>or if you would like to see historical log</p><pre>git log</pre><p>or if you would like to compare latest status to historical revision</p><pre>git diff &lt;put specific folder or file name if you would like to have specific under repo&gt;</pre><p>If you are ok with the change, back to step1 process resuming from staging by</p><pre style="line-height: 1.42857;">git add . git commit -m '&lt;your commit message here. if you use ' or " in side make sure not to be broken this message&gt;' git push origin master</pre><p style="line-height: 1.42857;"><br></p><p style="line-height: 1.42857;">This is how to update. In pt2, we will focus on how to create new branch and other miscellaneous operations</p><h3><br></h3><p><br></p>


<< Back to Blog Posts
Back to Home

Related Posts

Github Gist and Bl.ocks
Dec 11 2020
Explain how to use github gist and quick rendering d3.js from the page
Static web at Github Pages
Dec 14 2020
How to deploy static web pages at github.io pages
Git 101 : Github Basics Pt2
Jan 11 2021
This is pt 2 of github 101, focusing on branch and other miscellaneous but helpfull operations



© DATAK 2024