{"id":75226,"date":"2018-03-29T22:00:22","date_gmt":"2018-03-29T19:00:22","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=75226"},"modified":"2023-12-11T10:42:14","modified_gmt":"2023-12-11T08:42:14","slug":"git-tutorial-for-beginners","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html","title":{"rendered":"Git Tutorial for Beginners"},"content":{"rendered":"<h2>1. What is Git ?<\/h2>\n<p><a href=\"https:\/\/git-scm.com\/\">Git<\/a>\u00a0is a popular file versioning system used globally by numerous developers for their projects. It is lightweight and swift in its performance as compared to the likes. With a number of UI based tools to assist in Git based versioning, it has become extremely convenient for the developers to use Git Versioning System. Git flaunts features like Cheap local branching, convenient staging areas and multiple workflow configurations.<\/p>\n<p>In this article, we would specifically focus on getting\u00a0 started with using Git and cover up some basic commands that would be needed for a simple project. The article covers every detail of possible situations that might come up during the versioning. However, before beginning with it, it is necessary to have Git Version Control System(VCS) installed onto your system.<\/p>\n<h2>2. Git Installation<\/h2>\n<p>In order to install Git into your system, follow the steps shown below:<\/p>\n<h3>2.1 Installing Git in Windows &amp; MacOS<\/h3>\n<ol>\n<li>Go to the <a href=\"https:\/\/git-scm.com\/\">home page of Git VCS<\/a><\/li>\n<li>You should be able to find a download button for the latest Git version available<\/li>\n<li>Download and install the same<\/li>\n<\/ol>\n<p>In order to verify the installation, enter the below command in your command prompt(Windows) or Terminal(Mac OS).<\/p>\n<pre class=\"brush:bash\">$ git --version\n<\/pre>\n<p>An output as shown below should appear if the installation went fine.<\/p>\n<p><figure id=\"attachment_75291\" aria-describedby=\"caption-attachment-75291\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-26-at-1.39.33-PM.jpg\"><img decoding=\"async\" class=\"size-full wp-image-75291\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-26-at-1.39.33-PM.jpg\" alt=\"\" width=\"571\" height=\"363\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-26-at-1.39.33-PM.jpg 571w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-26-at-1.39.33-PM-300x191.jpg 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><figcaption id=\"caption-attachment-75291\" class=\"wp-caption-text\">Git Version Check<\/figcaption><\/figure><\/p>\n<h3>2.2 Installing Git Core in Linux<\/h3>\n<p>Git does not provide ready to install setup files for Linux. Hence, there is an alternate way to get it installed instead. Execute the below command from the terminal to get the <strong>git-core<\/strong> package installed.<\/p>\n<pre class=\"brush:bash\">$ sudo apt-get install git-core\n<\/pre>\n<p>This will do all the necessary steps and once it is ready, follow the below steps to verify the installation.<\/p>\n<p>Enter the below command in your Terminal window.<\/p>\n<pre class=\"brush:bash\">$ git --version\n<\/pre>\n<p>An output as shown above should appear if the installation went fine.<\/p>\n<p><figure id=\"attachment_75291\" aria-describedby=\"caption-attachment-75291\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-26-at-1.39.33-PM.jpg\"><img decoding=\"async\" class=\"size-full wp-image-75291\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-26-at-1.39.33-PM.jpg\" alt=\"\" width=\"571\" height=\"363\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-26-at-1.39.33-PM.jpg 571w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-26-at-1.39.33-PM-300x191.jpg 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><figcaption id=\"caption-attachment-75291\" class=\"wp-caption-text\">Git Version Check<\/figcaption><\/figure><\/p>\n<h2>3. Starting with the Git versioning<\/h2>\n<p>Once the installation is done and verified, we are all set to start with the first project versioning using Git. We would be working with a dummy Java project here to understand file versioning for a project better. You could use any popular IDE to create a Java project and get started. The IDE used here is Eclipse IDE. However, for the execution of commands, we would strictly restrict to the command line tools.<\/p>\n<h3>3.1 Creating and initialising a Git Repository<\/h3>\n<p>In order to configure a project to use Git based versioning system, all you need to do is initialise the project directory as a GIT repository. Create a Java project in your desired directory using your preferred IDE.<\/p>\n<p>Now, open up your terminal and change the directory to the project directory using the popular <code>cd<\/code> command.<\/p>\n<pre class=\"brush:bash\">$ cd \/path\/to\/project\n<\/pre>\n<p>To initialise the Git repository, execute the command <code>git init<\/code>. The output as shown below should be visible.<\/p>\n<pre class=\"brush:bash\">$ git init\nInitialized empty Git repository in \/Users\/abhishekkothari\/Desktop\/JavaCodeGeeks\/GitBeginners\/GitBeginner\/.git\/\n<\/pre>\n<p>As it can be seen, a <strong>.git<\/strong> directory is created in the project folder. This folder keeps a track of all the changes that take place locally. You can check the directory status by using the command <code>git status<\/code>. It should provide an output similar to what is shown below. It might vary if you are using a different IDE.<\/p>\n<pre class=\"brush:bash\">$ git status\nOn branch master\n\nNo commits yet\n\nUntracked files:\n  (use \"git add ...\" to include in what will be committed)\n\n\t.classpath\n\t.project\n\t.settings\/\n\tbin\/\n\tsrc\/\n<\/pre>\n<h3>3.2 Beginning with the file versioning<\/h3>\n<p>Now, in the project, create a Java file as shown below.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SayHello.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks;\n\npublic class SayHello {\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(\"Hello there!\");\n\t}\n}\n<\/pre>\n<p>The IDE might show error for the package. Feel free to remove the package declaration if not required. Once the file is created, we need to add the file to the GIT index. This would ascertain that the changes to the files are tracked thereafter. To add the file to the index, execute the command <code>git add \/path-to-file\/SayHello.java<\/code>. There would be no feedback to the command. However, you could check the status to ascertain the file is added to the index.<br \/>\nOn checking the status, an output similar to the one shown below will be visible.<\/p>\n<pre class=\"brush:bash\">$ git add src\/com\/javacodegeeks\/SayHello.java \n$ git status\nOn branch master\n\nNo commits yet\n\nChanges to be committed:\n  (use \"git rm --cached ...\" to unstage)\n\n\tnew file:   src\/com\/javacodegeeks\/SayHello.java\n\nUntracked files:\n  (use \"git add ...\" to include in what will be committed)\n\n\t.classpath\n\t.project\n\t.settings\/\n\tbin\/\n<\/pre>\n<p>The next step in the flow is to actually commit the file to the repository. A file being committed means the current version of file in the repository will be overwritten. A file can be committed using the command <code>git commit<\/code>. It is also possible to add comments describing the changes that are being committed. In order to do so, execute the command as shown below.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:bash\">$ git commit -m \"First File Committed\"<\/pre>\n<p>This would commit the file mentioning the comment <strong>First File Committed<\/strong> in the trace. An output similar to the one shown below should be visible.<\/p>\n<pre class=\"brush:bash\">$ git commit -m \"First File Committed\"\n[master (root-commit) 9cce524] First File Committed\n 1 file changed, 7 insertions(+)\n create mode 100644 src\/com\/javacodegeeks\/SayHello.java\n<\/pre>\n<h3>3.3 Working with multiple files<\/h3>\n<p>File versioning is generally used when there are multiple files to work with. Hence, certainly there needs to be ways to work easily with multiple files rather than executing the\u00a0<code>git add file-name<\/code> for each file to index every time. In order to understand the same, let&#8217;s create two more simple java files as shown under.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>EvenNumbers.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks;\n\npublic class EvenNumbers {\n\tpublic static void printEvenNumber(int i) {\n\t\tSystem.out.println(\"Even numbers upto \"+i);\n\t\tfor(int x=0;x&lt;i;x=x+2)\n\t\t\tSystem.out.println(x);\n\t}\n}\n\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>OddNumbers.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks;\n\npublic class OddNumbers {\n\tpublic static void printOddNumber(int i) {\n\t\tSystem.out.println(\"Odd numbers upto \"+i);\n\t\tfor(int x=1;x&lt;i;x=x+2)\n\t\t\tSystem.out.println(x);\n\t}\n}\n\n<\/pre>\n<p>Now, we need to add these two files to index without executing command for each file. In order to do so, there are two ways. One of them is useful when you specifically wish to add files with a specific extension. For instance,<\/p>\n<pre class=\"brush:bash\">$ git add *.java\n<\/pre>\n<p>The above command would add all the files with the extension <strong>.java<\/strong> to the staging. Staging is an area that holds the file version until it is committed. Another possible way is to add all the files that exist in the project using the below command.<\/p>\n<pre class=\"brush:bash\">$ git add -A\n<\/pre>\n<p>This command would take care of all the files &#8211; New, Modified as well as Deleted. Let&#8217;s now modify the file <code>SayHello.java<\/code> as shown below.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SayHello.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks;\n\npublic class SayHello {\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(\"Hello there!\");\n\t\tEvenNumbers.printEvenNumber(11);\n\t\tOddNumbers.printOddNumber(12);\n\t}\n}\n\n<\/pre>\n<p>Now execute either of the above commands to add all the Java files to the staging area and then check the status. The status should be similar to the one shown below:<\/p>\n<pre class=\"brush:bash\">$ git status\nOn branch master\nChanges to be committed:\n  (use \"git reset HEAD ...\" to unstage)\n\n\tnew file:   src\/com\/javacodegeeks\/EvenNumbers.java\n\tnew file:   src\/com\/javacodegeeks\/OddNumbers.java\n\tmodified:   src\/com\/javacodegeeks\/SayHello.java\n\nUntracked files:\n  (use \"git add ...\" to include in what will be committed)\n\n\t.classpath\n\t.project\n\t.settings\/\n\tbin\/\n<\/pre>\n<p>In case you used the command <code>git add -A<\/code>, it would have added all the empty directories to the index too. If this is not as expected, you can easily undo the movement to stage by executing <code>git reset<\/code>. It will reset the add action that was executed and revert the staging to the previous commit. An output similar to the one shown below will be available.<\/p>\n<pre class=\"brush:bash\">$ git reset\nUnstaged changes after reset:\nM\tsrc\/com\/javacodegeeks\/SayHello.java\n<\/pre>\n<p>Once reset, you can add the expected files to the staging and commit once things look fine.<br \/>\n[ulp id=&#8217;qqpFiv5a5W384Wlg&#8217;]<br \/>\n&nbsp;<\/p>\n<h3>3.4 Connecting to the remote repository<\/h3>\n<p>The changes tracked and stored during the above steps are all tracked locally. For now, the files are not available online for other developers to work on. In order to enable other developers to access or clone the code, it is important to connect the local code base to the remote repository. For this, you need to start by creating an online repository on popular Git hosting platforms like GitHub. For this article, I have created a repository <a href=\"https:\/\/github.com\/datsabk\/GitBeginner.git\">GitBeginner<\/a> on Github. To connect the local files to the repository execute the below command.<\/p>\n<pre class=\"brush:bash\">$ git remote add origin https:\/\/github.com\/datsabk\/GitBeginner.git\n<\/pre>\n<p>There would be no feedback for the command. However, you could check the successful connection by using below command.<\/p>\n<pre class=\"brush:bash\">$ git remote show origin\n* remote origin\n  Fetch URL: https:\/\/github.com\/datsabk\/GitBeginner.git\n  Push  URL: https:\/\/github.com\/datsabk\/GitBeginner.git\n  HEAD branch: (unknown)\n<\/pre>\n<p>Now that the local files are connected to the remote repository, it&#8217;s time to push the files to the repository. To do so, execute the command shown below:<\/p>\n<pre class=\"brush:bash\">$ git push -u origin master\nCounting objects: 6, done.\nDelta compression using up to 4 threads.\nCompressing objects: 100% (2\/2), done.\nWriting objects: 100% (6\/6), 471 bytes | 157.00 KiB\/s, done.\nTotal 6 (delta 0), reused 0 (delta 0)\nTo https:\/\/github.com\/datsabk\/GitBeginner.git\n * [new branch]      master -&gt; master\nBranch 'master' set up to track remote branch 'master' from 'origin'.\n<\/pre>\n<p>Incase, you did not configure Git for the user details, you would be prompted to enter the credentials for your corresponding hosting account. You can configure your Git user name and password by following steps from this <a href=\"https:\/\/help.github.com\/articles\/setting-your-username-in-git\/\">link<\/a>.<\/p>\n<h3>3.5 Git Branching and Merging<\/h3>\n<p>In a large project, the developers do not usually work on a common branch. Every developer creates a branch with respect to the feature they are developing or the bug they are trying to resolve. This section covers the process of creating a branch and merging the same into the main branch.<\/p>\n<p>First of all, let&#8217;s create a local branch. In order to create a new local branch, execute the command <code>git checkout -b newbranch<\/code>. This will create a new local branch and switch to it. An output similar to the one shown below will be available.<\/p>\n<pre class=\"brush:bash\">$ git checkout -b newbranch\nM\tsrc\/com\/javacodegeeks\/SayHello.java\nSwitched to a new branch 'newbranch'\n<\/pre>\n<p>Now, let us change some code in <code>SayHello.java<\/code> as shown below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SayHello.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks;\n\npublic class SayHello {\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(\"Hello there!\");\n\t\tSystem.out.println(\"Printing even numbers\");\n\t\tEvenNumbers.printEvenNumber(11);\n\t\tSystem.out.println(\"Printing odd numbers\");\n\t\tOddNumbers.printOddNumber(12);\n\t}\n}\n<\/pre>\n<p>The developers occasionally need to check the differences between the files at the remote repository. Whenever this is required, simply execute the command <code>git diff<\/code> to check all the modifications. An output similar to the one shown below will turn up.<\/p>\n<pre class=\"brush:bash\">$ git diff\ndiff --git a\/bin\/com\/javacodegeeks\/SayHello.class b\/bin\/com\/javacodegeeks\/SayHello.class\nindex 0e9d8e3..6c45444 100644\nBinary files a\/bin\/com\/javacodegeeks\/SayHello.class and b\/bin\/com\/javacodegeeks\/SayHello.class differ\ndiff --git a\/src\/com\/javacodegeeks\/SayHello.java b\/src\/com\/javacodegeeks\/SayHello.java\nindex 815b53a..4276f44 100644\n--- a\/src\/com\/javacodegeeks\/SayHello.java\n+++ b\/src\/com\/javacodegeeks\/SayHello.java\n@@ -3,7 +3,9 @@ package com.javacodegeeks;\n public class SayHello {\n        public static void main(String[] args) {\n                System.out.println(\"Hello there!\");\n+               System.out.println(\"Printing Even numbers\");\n                EvenNumbers.printEvenNumber(11);\n+               System.out.println(\"Printing Odd numbers\");\n                OddNumbers.printOddNumber(12);\n        }\n }\n\n<\/pre>\n<p>As it can be noticed, there are <strong>+<\/strong> signs to indicate that the two lines were added. For the <strong>.class<\/strong> files, Git is unable to read them as text since they are binary byte codes. Hence, it merely says that they are different from what was committed earlier. Now, its time to push these changes and merge them to the master branch. The procedure to push the changes to the remote repository remains the same. Execute the commands as shown below:<\/p>\n<pre class=\"brush:bash\">$ git commit -m \"Added two lines\"\n[newbranch 3f7d0cb] Added two lines\n 1 file changed, 2 insertions(+)\nMacBook-Air:GitBeginner abhishekkothari$ git push -u origin newbranch\nCounting objects: 24, done.\nDelta compression using up to 4 threads.\nCompressing objects: 100% (18\/18), done.\nWriting objects: 100% (24\/24), 3.09 KiB | 791.00 KiB\/s, done.\nTotal 24 (delta 5), reused 0 (delta 0)\nremote: Resolving deltas: 100% (5\/5), done.\nTo https:\/\/github.com\/datsabk\/GitBeginner.git\n * [new branch]      newbranch -&gt; newbranch\nBranch 'newbranch' set up to track remote branch 'newbranch' from 'origin'.\n<\/pre>\n<p>Now the new branch has been created on the remote repository and the changes are pushed to the branch. However, the changes are not yet available in the master branch. In order to pull these changes into the master branch, raise a merge request using the Github UI as shown below.<\/p>\n<p><figure id=\"attachment_75290\" aria-describedby=\"caption-attachment-75290\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-27-at-1.20.50-AM-e1522094148223.jpg\"><img decoding=\"async\" class=\"size-full wp-image-75290\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-27-at-1.20.50-AM-e1522094148223.jpg\" alt=\"\" width=\"800\" height=\"423\" \/><\/a><figcaption id=\"caption-attachment-75290\" class=\"wp-caption-text\">Raising Merge Request<\/figcaption><\/figure><\/p>\n<p>Once the merge request has been raised, an authorised person can accept the request and pull the changes into the master repository and make it available to others. In a large project, there are frequent chances of having conflicts during merge. Conflicts occur when some other developer already merged the changes in a file that you are trying to merge. In such a case, Git is unable to decide whether the changes should be overwritten or merged.<\/p>\n<p>A conflicting scenario has been generated in the above pull request by editing the\u00a0<strong>SayHello.java<\/strong> file in the master branch as shown below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SayHello.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks;\n\npublic class SayHello {\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(\"Hi there!\");\n\t}\n}\n<\/pre>\n<p>Once this change has been done, the pull request shows conflict as shown below:<\/p>\n<p><figure id=\"attachment_75331\" aria-describedby=\"caption-attachment-75331\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-28-at-12.25.34-AM.jpg\"><img decoding=\"async\" class=\"wp-image-75331\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-28-at-12.25.34-AM.jpg\" alt=\"\" width=\"820\" height=\"282\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-28-at-12.25.34-AM.jpg 830w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-28-at-12.25.34-AM-300x103.jpg 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/Screen-Shot-2018-03-28-at-12.25.34-AM-768x264.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-75331\" class=\"wp-caption-text\">Merge Conflict in Git<\/figcaption><\/figure><\/p>\n<p>These conflicts can be interactively resolved by clicking the Resolve conflicts and selecting the code that needs to be written to the file once merged. Such conflicts can be challenging at times. Hence, it is advisable to pull the latest changes to the files incrementally to avoid large chunk of conflicting code. The latest changes of any specific branch can be pulled by using the commands shown below:<\/p>\n<pre class=\"brush:bash\">$ git fetch origin\n$ git merge origin\/master\n<\/pre>\n<p>The first command will pull the latest changes of the respective branch. The next command does the job of merging the fetched changes into the local files.<\/p>\n<h3>3.6 Ignoring certain files<\/h3>\n<p>In the previous operations, we sticked to the <code>git add *.java<\/code> command. However, this is not the case always. There might be a need where we wish to ignore only certain files rather than all. In such a case, below command comes in handy.<\/p>\n<pre class=\"brush:bash\">$ git rm -r --cached *.class\n<\/pre>\n<p>On executing the above command and then checking the status of the repository, you would find that the class files are now being ignored and the output of <code>git status<\/code> is similar to the one shown below.<\/p>\n<pre class=\"brush:bash\">$ git status\nOn branch newbranch\nYour branch is up to date with 'origin\/newbranch'.\n\nChanges to be committed:\n  (use \"git reset HEAD ...\" to unstage)\n\n\tdeleted:    bin\/com\/javacodegeeks\/EvenNumbers.class\n\tdeleted:    bin\/com\/javacodegeeks\/OddNumbers.class\n\tdeleted:    bin\/com\/javacodegeeks\/SayHello.class\n\nUntracked files:\n  (use \"git add ...\" to include in what will be committed)\n\n\tbin\/\n<\/pre>\n<p>It indicates that the class files are deleted from the tracking list and the bin folder is now not being tracked. Thus, the files are now in the ignored list. This list can be found in .gitignore file located in the project directory.<\/p>\n<h2>4. Conclusion<\/h2>\n<p>The article has covered in depth the complete process of creating and managing Git repository for a project as a beginner. It captures the basic problems or features that a developer might come across. There would be complex challenges ahead. However, Git being a popular versioning system, there should be sufficient help available for the same.<\/p>\n<h2>5. References<\/h2>\n<ul>\n<li><a href=\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/popular-git-commands-examples\/\">Details of some Basic commands\u00a0<\/a><\/li>\n<li><a href=\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/best-git-clients-linux-windows\/\">GIT GUI clients to make your job easy<\/a><\/li>\n<li><a href=\"https:\/\/try.github.io\/\">Interactive tutorial for GIT command line<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>1. What is Git ? Git\u00a0is a popular file versioning system used globally by numerous developers for their projects. It is lightweight and swift in its performance as compared to the likes. With a number of UI based tools to assist in Git based versioning, it has become extremely convenient for the developers to use &hellip;<\/p>\n","protected":false},"author":21944,"featured_media":118,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[334,397],"class_list":["post-75226","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-development","tag-git","tag-versioning"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Git Tutorial for Beginners - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. What is Git ? Git\u00a0is a popular file versioning system used globally by numerous developers for their projects. It is lightweight and swift in its\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Git Tutorial for Beginners - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. What is Git ? Git\u00a0is a popular file versioning system used globally by numerous developers for their projects. It is lightweight and swift in its\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-29T19:00:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-11T08:42:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/git-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Abhishek Kothari\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Abhishek Kothari\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/git-tutorial-for-beginners.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/git-tutorial-for-beginners.html\"},\"author\":{\"name\":\"Abhishek Kothari\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/308db426d5e31fe272944e267861c55a\"},\"headline\":\"Git Tutorial for Beginners\",\"datePublished\":\"2018-03-29T19:00:22+00:00\",\"dateModified\":\"2023-12-11T08:42:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/git-tutorial-for-beginners.html\"},\"wordCount\":1922,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/git-tutorial-for-beginners.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/git-logo.jpg\",\"keywords\":[\"Git\",\"Versioning\"],\"articleSection\":[\"Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/git-tutorial-for-beginners.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/git-tutorial-for-beginners.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/git-tutorial-for-beginners.html\",\"name\":\"Git Tutorial for Beginners - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/git-tutorial-for-beginners.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/git-tutorial-for-beginners.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/git-logo.jpg\",\"datePublished\":\"2018-03-29T19:00:22+00:00\",\"dateModified\":\"2023-12-11T08:42:14+00:00\",\"description\":\"1. What is Git ? Git\u00a0is a popular file versioning system used globally by numerous developers for their projects. It is lightweight and swift in its\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/git-tutorial-for-beginners.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/git-tutorial-for-beginners.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/git-tutorial-for-beginners.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/git-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/git-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/git-tutorial-for-beginners.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Software Development\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/software-development\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Git Tutorial for Beginners\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/308db426d5e31fe272944e267861c55a\",\"name\":\"Abhishek Kothari\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0330027588516ca573c97a060605ee7e7b99fc40fd0037cf8d1bf5166b4e4bd6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0330027588516ca573c97a060605ee7e7b99fc40fd0037cf8d1bf5166b4e4bd6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0330027588516ca573c97a060605ee7e7b99fc40fd0037cf8d1bf5166b4e4bd6?s=96&d=mm&r=g\",\"caption\":\"Abhishek Kothari\"},\"description\":\"Abhishek is a Web Developer with diverse skills across multiple Web development technologies. During his professional career, he has worked on numerous enterprise level applications and understood the technological architecture and complexities involved in making an exceptional project. His passion to share knowledge among the community through various mediums has led him towards being a Professional Online Trainer, Youtuber as well as Technical Content Writer.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/abhishek-kothari\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Git Tutorial for Beginners - Java Code Geeks","description":"1. What is Git ? Git\u00a0is a popular file versioning system used globally by numerous developers for their projects. It is lightweight and swift in its","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html","og_locale":"en_US","og_type":"article","og_title":"Git Tutorial for Beginners - Java Code Geeks","og_description":"1. What is Git ? Git\u00a0is a popular file versioning system used globally by numerous developers for their projects. It is lightweight and swift in its","og_url":"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2018-03-29T19:00:22+00:00","article_modified_time":"2023-12-11T08:42:14+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/git-logo.jpg","type":"image\/jpeg"}],"author":"Abhishek Kothari","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Abhishek Kothari","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html"},"author":{"name":"Abhishek Kothari","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/308db426d5e31fe272944e267861c55a"},"headline":"Git Tutorial for Beginners","datePublished":"2018-03-29T19:00:22+00:00","dateModified":"2023-12-11T08:42:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html"},"wordCount":1922,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/git-logo.jpg","keywords":["Git","Versioning"],"articleSection":["Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html","url":"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html","name":"Git Tutorial for Beginners - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/git-logo.jpg","datePublished":"2018-03-29T19:00:22+00:00","dateModified":"2023-12-11T08:42:14+00:00","description":"1. What is Git ? Git\u00a0is a popular file versioning system used globally by numerous developers for their projects. It is lightweight and swift in its","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/git-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/git-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/git-tutorial-for-beginners.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Software Development","item":"https:\/\/www.javacodegeeks.com\/category\/software-development"},{"@type":"ListItem","position":3,"name":"Git Tutorial for Beginners"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/308db426d5e31fe272944e267861c55a","name":"Abhishek Kothari","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0330027588516ca573c97a060605ee7e7b99fc40fd0037cf8d1bf5166b4e4bd6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0330027588516ca573c97a060605ee7e7b99fc40fd0037cf8d1bf5166b4e4bd6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0330027588516ca573c97a060605ee7e7b99fc40fd0037cf8d1bf5166b4e4bd6?s=96&d=mm&r=g","caption":"Abhishek Kothari"},"description":"Abhishek is a Web Developer with diverse skills across multiple Web development technologies. During his professional career, he has worked on numerous enterprise level applications and understood the technological architecture and complexities involved in making an exceptional project. His passion to share knowledge among the community through various mediums has led him towards being a Professional Online Trainer, Youtuber as well as Technical Content Writer.","url":"https:\/\/www.javacodegeeks.com\/author\/abhishek-kothari"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/75226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/21944"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=75226"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/75226\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/118"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=75226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=75226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=75226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}