{"id":675,"date":"2022-02-16T17:01:08","date_gmt":"2022-02-16T22:01:08","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=675"},"modified":"2024-02-08T08:39:57","modified_gmt":"2024-02-08T13:39:57","slug":"getting-started-with-git","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/getting-started-with-git\/","title":{"rendered":"Getting started with GIT"},"content":{"rendered":"\n<p>A version control system keeps track of changes in code. It keeps track of every change made by every developer. It allows code bases to be branched and then merged back. You can also go back in time to a point before you introduced something in the code. Version control is absolutely essential for software development.<\/p>\n\n\n\n<p>Git is a version control system developed by Linus Torvalds, the creator of Linux kernel. It is a distributed version control system as opposed to a central version control system. Subversion and CVS store the code in a central repository which is accessed by all developers. In Git, every developer copy of repository contains full history. There is still a canonical repository but individual developer don&#8217;t need to access server resources for their work as all their changes managed by their local repository. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Linus clones central repository\nLinus checks out a branch in the repository\nLinus makes code changes and commits to local respository about 20+ times per day\nWhen Linus is satisfied that his code is good enough, he pushes code to central repository\n<\/code><\/pre>\n\n\n\n<p>The code for this would look something like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git clone https:\/\/github.com\/nazimrahman\/xmlsplitter.git\ngit checkout dev\ngit add -A; git commit -m \"did this for this reason\"\ngit push origin dev\n<\/code><\/pre>\n\n\n\n<p>We will cover each of this in sufficent detail.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"installing-git\">Installing Git<\/h3>\n\n\n\n<p>Git is free and opensource.<\/p>\n\n\n\n<p>To install git on Windows, I would recommend that you simply download and install <a href=\"https:\/\/git-scm.com\/downloads\">git bash<\/a><\/p>\n\n\n\n<p>To install git on Mac, download and install from <a href=\"https:\/\/git-scm.com\/downloads\">git-scm.com<\/a><\/p>\n\n\n\n<p>To install git on Ubuntu Linux, simply type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install git\n<\/code><\/pre>\n\n\n\n<p>To test whether git install correctly on any operating system, simply go to the terminal and type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>which git\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"cloning-the-central-repository\">Cloning the central repository<\/h3>\n\n\n\n<p>Cloning a repository means downloading a local copy. To clone, simply type the following with the relevant git url:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git clone https:\/\/github.com\/nazimrahman\/xmlsplitter.git\n<\/code><\/pre>\n\n\n\n<p>This creates a local repository on your system.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"checking-out-a-branch\">Checking out a branch<\/h3>\n\n\n\n<p>When working with your repository, you need to check out a branch as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git checkout dev\n<\/code><\/pre>\n\n\n\n<p>where your branch is dev.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"add-removing-your-changes\">Add\/Removing your changes<\/h3>\n\n\n\n<p>To tell git about a new file you added or a file you updated, simply do the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git add README.md\ngit add somedirectory\ngit add -A\n<\/code><\/pre>\n\n\n\n<p>The first command is to add a file. The second to add a directory. The third is to add everything. The following command removes a file from git.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git remove README.md\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"commiting-a-change\">Commiting a change<\/h3>\n\n\n\n<p>The following command allows you to commit your changes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git commit -m \"I changed this for this reason\"\n<\/code><\/pre>\n\n\n\n<p>The text following -m is the commit comment. It is very important to take a moment and write a meaningful commit comment. This is what your future self will read when you will have to revert changes or isolate the change that caused something to break.<\/p>\n\n\n\n<p>It is good habit to check status before committing.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git status\n<\/code><\/pre>\n\n\n\n<p>This command basically tells you which files will be committed. This is a good time to verify that only the files you intended to modify are being committed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"pushing-your-code-to-central-repository\">Pushing your code to central repository<\/h3>\n\n\n\n<p>When you are satisified that your code is good enough to be shared with your colleagues, push the code to the central repository as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git push origin dev\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h3>\n\n\n\n<p>There is much more to GIT. This is a quick startup for beginners. Most organizations have a workflow that all developers are expected to follow. Git is a bit different from Subversion and CVS. If you are merging, stashing, or rebasing, read and understand the documentation before you proceed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A version control system keeps track of changes in code. It keeps track of every change made by every developer. It allows code bases to be branched and then merged back. You can also go back in time to a point before you introduced something in the code. Version control is absolutely essential for software [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[512],"tags":[76,354],"class_list":["post-675","post","type-post","status-publish","format-standard","hentry","category-misc","tag-programming","tag-versioning"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=675"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/675\/revisions"}],"predecessor-version":[{"id":676,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/675\/revisions\/676"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}