{"id":45221,"date":"2017-06-02T11:00:42","date_gmt":"2017-06-02T08:00:42","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=45221"},"modified":"2019-04-23T14:23:07","modified_gmt":"2019-04-23T11:23:07","slug":"git-commands-tutorial","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/","title":{"rendered":"Git Commands Tutorial"},"content":{"rendered":"<p>If you are a software developer, there is a pretty good chance that you must have used version control software in one form or the other. Git has surged in popularity over the past few years&nbsp;succeeding SVN and CVS. With almost every open source project migrated to Git as a version control of choice, it currently seems like a de-facto standard for the version control in the programming community.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;\n<\/p>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nYou may skip the introductory part and jump directly to the <a href=\"#tutorial\"><strong>commands tutorial<\/strong><\/a> below.<\/div>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#VC\">1. What is version control?<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#benefits\">1.1 Benefits of VCS<\/a><\/dt>\n<dt><a href=\"#comparison\">1.2 Centralized Vs Distributed VCS<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#WhyGit\">2. Why Git?<\/a><\/dt>\n<dt><a href=\"#install\">3. Installing Git Client<\/a><\/dt>\n<dt><a href=\"#tutorial\">4. Git Commands<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#config\">4.1 Initial Git Configuration [git config]<\/a><\/dt>\n<dt><a href=\"#help\">4.2 Asking Git for help [git help]<\/a><\/dt>\n<dt><a href=\"#init\">4.3 Creating a new repository [git init]<\/a><\/dt>\n<dt><a href=\"#clone\">4.4 Checking out existing repository [git clone]<\/a><\/dt>\n<dt><a href=\"#status\">4.5 Check the status of your project [git status]<\/a><\/dt>\n<dt><a href=\"#add\">4.6 Start tracking new files [git add]<\/a><\/dt>\n<dt><a href=\"#ignore\">4.7 Files never to be committed [git ignore]<\/a><\/dt>\n<dt><a href=\"#diff\">4.8 What exactly got changed [git diff]<\/a><\/dt>\n<dt><a href=\"#commit\">4.9 Commit your changes [git commit]<\/a><\/dt>\n<dt><a href=\"#rm\">4.10 Removing and Deleting tracked files [git rm]<\/a><\/dt>\n<dt><a href=\"#mv\">4.11 Tracking renamed files [git mv]<\/a><\/dt>\n<dt><a href=\"#log\">4.12 Show me the history [git log]<\/a><\/dt>\n<dt><a href=\"#remote\">4.13 Show me the remote location [git remote]<\/a><\/dt>\n<dt><a href=\"#fetch\">4.14 Get Remote Data\/Files [git fetch, git pull]<\/a><\/dt>\n<dt><a href=\"#push\">4.15 Send local changes to remote [git push]<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#summary\">5. Summary<\/a><\/dt>\n<dt><a href=\"#references\">6. References<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2 id=\"VC\">1. What is version control?<\/h2>\n<p>Version control (a.k.a Version Control System or VCS) is a system that records changes to a file or set of files over time so that you can recall specific versions later. It keeps the entire change history of your project file by file which you call changeset.<\/p>\n<h3 id=\"benefits\">1.1 Benefits of VCS:<\/h3>\n<p>You need version control so that:<\/p>\n<ol>\n<li>you can revert back to to last working edition of the file or the complete code in the event of a failure or error<\/li>\n<li>multiple parties can work in a collaborative way over one code base; they don&#8217;t need to share pieces of code or patches. VCS helps merging the code from many developers easier.<\/li>\n<li>developers don&#8217;t need to comment out certain pieces of code to disable certain functionality. They can maintain different versions of the same codebase containing different changes which can be merged with the main repository when desired.<\/li>\n<\/ol>\n<h3 id=\"comparison\">1.2 Centralized Vs Distributed VCS<\/h3>\n<p>VCS like SVN and CVS are examples of Centralized VCS (CVCS) while Git is a Distributed VCS (DVCS).<\/p>\n<p>CVCS has only one single place where full version history of the software is maintained. In DVCS, every developer&#8217;s working copy of the code is also a repository that can contain the full history of all changes.<\/p>\n<p>CVCS being centralized has single point of failure.&nbsp;If that server goes down for an hour, then during that hour nobody can collaborate at all or save versioned changes to anything they\u2019re working on.<\/p>\n<p>In a DVCS (such as Git, Mercurial, Bazaar or Darcs), clients don\u2019t just check out the latest snapshot of the files: they fully mirror the repository. Thus if any server dies, and these systems were collaborating via it, any of the client repositories can be copied back up to the server to restore it. Every clone is really a full backup of all the data.<\/p>\n<p>Furthermore, many of these systems deal pretty well with having several remote repositories they can work with, so you can collaborate with different groups of people in different ways simultaneously within the same project. This allows you to set up several types of workflows that aren\u2019t possible in centralized systems, such as hierarchical models.<sup>[<a href=\"https:\/\/git-scm.com\/book\/en\/v2\/Getting-Started-About-Version-Control\">1<\/a>]<\/sup><\/p>\n<h2 id=\"WhyGit\">2. Why Git?<\/h2>\n<p>While many VCS are in existence today, Git has fast picked up pace as a version control of choice especially by the open source programming community.<\/p>\n<ol>\n<li><strong>Distributed<\/strong> &#8211;&nbsp;This is at the heart of Git and is a fundamental concept in Git. In CVCS like SVN, SVN keeps the track of all the changes in a central repository and all the clients contain no change history, if the master repository is lost all the history is lost. Git, on the other hand, is a DVCS. Every client has the complete history of all the changes.<\/li>\n<li><b>Speed (Fast branching and merging) &#8211;&nbsp;<\/b>In Subversion, branch creation was easy but it used to get created as another directory. When you need to switch to a different branch, it is like switching to a different codebase which consumes a lot of time and also a lot of space on your local machine. Unlike SVN, Git contains just a single copy for all the branches and switching from one branch to another happens in a breeze; saves both time and space.<\/li>\n<li><strong>&nbsp;Strong support for non-linear development (thousands of parallel branches) &#8211;&nbsp;<\/strong>Git stores all the information of different branches locally as well in a single copy and not creating a cloned copy for every branch results in a lot of space saving. Thus developers have come up with unique development models like creating a new branch for every enhancement and\/or bugfix annotating them as such; thus making the release management process easier.<\/li>\n<\/ol>\n<h2 id=\"install\">3. Installing Git Client<\/h2>\n<p>For the purpose of this tutorial we are going to use the following tools on a Windows 10 platform:<\/p>\n<ol>\n<li><span style=\"text-decoration: underline;\"><strong>Git Bash<\/strong><\/span> &#8211; It is the command line tool for Git. We will use all our commands for the purpose of this tutorial from this tool.&nbsp;The most official build is available for download on the Git website. Just go to <a class=\"bare\" href=\"http:\/\/git-scm.com\/download\/win\">http:\/\/git-scm.com\/download\/win<\/a> and the download will start automatically. Note that this is a project called Git for Windows, which is separate from Git itself; for more information on it, go to <a class=\"bare\" href=\"https:\/\/git-for-windows.github.io\/\">https:\/\/git-for-windows.github.io\/<\/a>. <em>You may refer this <a href=\"https:\/\/git-scm.com\/book\/en\/v2\/Getting-Started-Installing-Git\">page <\/a>for installation on other platforms. Please note, irrespective of the platform used, the git commands remain the same.<\/em><\/li>\n<li><span style=\"text-decoration: underline;\"><strong>GitHub<\/strong><\/span> &#8211; This is going to serve as the remote location where we will keep our code\/files for this tutorial. Go to&nbsp;<a href=\"https:\/\/github.com\/\">https:\/\/github.com\/<\/a> and create an account. You can create public and private repositories here which can then be accessed from anywhere as long as you have an internet connection.<\/li>\n<\/ol>\n<h2><span id=\"tutorial\">4. Git Commands<\/span><\/h2>\n<p>There are a lot of different ways to use Git. There are the original command line tools, and there are many graphical user interfaces of varying capabilities. This tutorial provides a succinct overview of the most important Git commands.<\/p>\n<p>All the commands will be run in Git Bash.<\/p>\n<p>Before beginning with the commands, let&#8217;s create our first repository on Github:<\/p>\n<ol>\n<li>Once you have created your account, you should see this page on&nbsp;<a href=\"https:\/\/github.com\/\">https:\/\/github.com\/<\/a>.\n<p><figure id=\"attachment_46890\" aria-describedby=\"caption-attachment-46890\" style=\"width: 858px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/Github-main.png\"><img decoding=\"async\" class=\"wp-image-46890 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/Github-main.png\" alt=\"\" width=\"858\" height=\"537\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/Github-main.png 858w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/Github-main-300x188.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/Github-main-768x481.png 768w\" sizes=\"(max-width: 858px) 100vw, 858px\" \/><\/a><figcaption id=\"caption-attachment-46890\" class=\"wp-caption-text\">Github Welcome Page<\/figcaption><\/figure><\/li>\n<li>Click on &#8220;Start a project&#8221; and you will taken to screen with the following options.\n<p><figure id=\"attachment_46759\" aria-describedby=\"caption-attachment-46759\" style=\"width: 725px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/create-repo.png\"><img decoding=\"async\" class=\"wp-image-46759 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/create-repo.png\" alt=\"\" width=\"725\" height=\"604\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/create-repo.png 725w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/create-repo-300x250.png 300w\" sizes=\"(max-width: 725px) 100vw, 725px\" \/><\/a><figcaption id=\"caption-attachment-46759\" class=\"wp-caption-text\">Create New Repository on Github<\/figcaption><\/figure><\/li>\n<li>Put repository name as &#8220;git-commands-tutorial&#8221; and a description. You may mark the repository as public or private. If marked private, it&nbsp;will be accessible only to those you want to. Click on create repository, you will see screen like this.\n<p><figure id=\"attachment_46891\" aria-describedby=\"caption-attachment-46891\" style=\"width: 852px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/new-repo-next-screen.png\"><img decoding=\"async\" class=\"wp-image-46891 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/new-repo-next-screen.png\" alt=\"\" width=\"852\" height=\"563\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/new-repo-next-screen.png 852w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/new-repo-next-screen-300x198.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/new-repo-next-screen-768x507.png 768w\" sizes=\"(max-width: 852px) 100vw, 852px\" \/><\/a><figcaption id=\"caption-attachment-46891\" class=\"wp-caption-text\">Repository Created Screen<\/figcaption><\/figure><\/li>\n<li>Click on README link and it will take you to another page. Rename README.md to project-plan.txt. Scroll down a bit and put comments for the commit &#8211; &#8220;creating project-plan.txt&#8221;. Click &#8220;Commit New File&#8221; and your first commit to git repository will be there. We will later do the same through command.<\/li>\n<\/ol>\n<h3 id=\"config\">4.1&nbsp;Initial Git Configuration [git config]<\/h3>\n<p>Git comes with a tool called <code>git config<\/code> that lets you get and set configuration variables that control all aspects of how Git looks and operates.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>The first thing you should do when you install Git is to set your user name and email address. This is important because every Git commit uses this information.<\/p>\n<pre class=\"brush:bash\">git config --global user.name \"Mayank Gupta\"\n\ngit config --global user.email \"mayankbindas@gmail.com\"\n<\/pre>\n<p>You can set global settings or project specific settings with the help of this command. If you want to override this with a different name or email address for specific projects, you can run the command without the <code>--global<\/code> option when you\u2019re in that project.<\/p>\n<p>If you want to check your settings, you can use the <code>git config --list<\/code> command to list all the settings Git can find at that point.<\/p>\n<p>You can also check what Git thinks a specific key\u2019s value is by typing <code>git config &lt;key&gt;.<\/code><\/p>\n<h3 id=\"help\">4.2 Asking Git for help [git help]<\/h3>\n<p>There are three ways to get the manual help page or manpage for any git command:<\/p>\n<pre class=\"brush:bash\">git help &lt;verb&gt;\n\ngit &lt;verb&gt; --help\n\nman git-&lt;verb&gt;<\/pre>\n<p>For example, if we want help on config command, we have the following three options:<\/p>\n<pre class=\"brush:bash\">git help config\n\ngit config --help\n\nman git-help\n<\/pre>\n<p>Try all of them out before proceeding further. Running this command on Windows will open a very long help page dedicated to this particular command in your default browser even if you are offline something like this.<\/p>\n<p><figure id=\"attachment_46889\" aria-describedby=\"caption-attachment-46889\" style=\"width: 854px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/git-config.png\"><img decoding=\"async\" class=\"wp-image-46889 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/git-config.png\" alt=\"\" width=\"854\" height=\"572\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/git-config.png 854w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/git-config-300x201.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/git-config-768x514.png 768w\" sizes=\"(max-width: 854px) 100vw, 854px\" \/><\/a><figcaption id=\"caption-attachment-46889\" class=\"wp-caption-text\">Git Man Page<\/figcaption><\/figure><\/p>\n<h3 id=\"init\">4.3 Creating a new repository [git init]<\/h3>\n<p>git init is used to convert a project or a file system&nbsp;into a Git project. Go to an existing directory on your file system and type git init.<\/p>\n<p>The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new empty repository.<\/p>\n<p>Executing git init creates a .git subdirectory in the project root, which contains all of the necessary metadata for the repo. Aside from the .git directory, an existing project remains unaltered (unlike SVN, Git doesn&#8217;t require a .git folder in every subdirectory).<\/p>\n<p>However, for most projects, git init only needs to be executed once to create a central repository\u2014developers typically don&#8217;t use git init to create their local repositories.<\/p>\n<p>Since we have created our project using Github, we&nbsp;will skip to run this command.<\/p>\n<h3 id=\"clone\">4.4 Checking out existing repository [git clone]<\/h3>\n<p>Create a folder called &#8220;git-repository&#8221; on your Windows machine. Go inside this folder and right click, you will see &#8220;Git Bash Here&#8221; as one of the option. Click on it. Git Bash will open and we will run all our git commands in it.<\/p>\n<p>Type the following command and this will checkout our project created on github.<\/p>\n<p><figure id=\"attachment_46848\" aria-describedby=\"caption-attachment-46848\" style=\"width: 582px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-clone.png\"><img decoding=\"async\" class=\"wp-image-46848 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-clone.png\" alt=\"\" width=\"582\" height=\"276\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-clone.png 582w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-clone-300x142.png 300w\" sizes=\"(max-width: 582px) 100vw, 582px\" \/><\/a><figcaption id=\"caption-attachment-46848\" class=\"wp-caption-text\">git clone<\/figcaption><\/figure><\/p>\n<blockquote>\n<p>In the lifecycle of a project, git init, git clone are mostly one time operations. git config (with global settings) is also mostly a one time operation on your system.<\/p>\n<\/blockquote>\n<h3 id=\"status\">4.5 Check the status of your project [git status]<\/h3>\n<p>Run git status in Git Bash. You will see an output like this<\/p>\n<p><figure id=\"attachment_46849\" aria-describedby=\"caption-attachment-46849\" style=\"width: 579px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status.png\"><img decoding=\"async\" class=\"wp-image-46849 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status.png\" alt=\"\" width=\"579\" height=\"323\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status.png 579w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status-300x167.png 300w\" sizes=\"(max-width: 579px) 100vw, 579px\" \/><\/a><figcaption id=\"caption-attachment-46849\" class=\"wp-caption-text\">git status<\/figcaption><\/figure><\/p>\n<p>Running git status shows you which files are ignored (untracked files), which files are modified and needs to be committed. Currently we don&#8217;t have a clean directory with no modified tracked files and nop untracked files. We will continue to explore git status more as we use other commands.<\/p>\n<p>Let&#8217;s create a new file called &#8220;README.txt&#8221; and run git status again.<\/p>\n<p><figure id=\"attachment_46850\" aria-describedby=\"caption-attachment-46850\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status1.png\"><img decoding=\"async\" class=\"wp-image-46850 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status1.png\" alt=\"\" width=\"580\" height=\"319\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status1.png 580w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status1-300x165.png 300w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/a><figcaption id=\"caption-attachment-46850\" class=\"wp-caption-text\">git status &#8211; Untracked Files<\/figcaption><\/figure><\/p>\n<p>README.txt is untracked file for now.<\/p>\n<h3 id=\"add\">4.6 Start tracking new files [git add]<\/h3>\n<p>Untracked file means they are new files (weren&#8217;t present in the last snapshot or commit). Git won&#8217;t start tracking it unless it is explicitly told to do so. To start tracking new files, you run<\/p>\n<pre class=\"brush:bash\">git add README.txt\n<\/pre>\n<p>Git will start tracking changes to README.txt from now on. Let&#8217;s run git status now.<\/p>\n<p><figure id=\"attachment_46851\" aria-describedby=\"caption-attachment-46851\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status2.png\"><img decoding=\"async\" class=\"wp-image-46851 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status2.png\" alt=\"\" width=\"580\" height=\"321\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status2.png 580w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status2-300x166.png 300w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/a><figcaption id=\"caption-attachment-46851\" class=\"wp-caption-text\">git add<\/figcaption><\/figure><\/p>\n<p>The git add command takes a path name for either a file or a directory; if it\u2019s a directory, the command adds all the files in that directory recursively.<\/p>\n<p>git add is also used to stage an existing file which was being tracked previously and has been modified. It is often called termed as &#8220;add this content to the next commit\u201d rather than \u201cadd this file to the project\u201d.<\/p>\n<p>Let&#8217;s modify the project-plan.txt file by adding a new line &#8220;dummy project plan&#8221; to it. Let&#8217;s run git status now.<\/p>\n<p><figure id=\"attachment_46852\" aria-describedby=\"caption-attachment-46852\" style=\"width: 581px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status3.png\"><img decoding=\"async\" class=\"wp-image-46852 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status3.png\" alt=\"\" width=\"581\" height=\"322\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status3.png 581w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status3-300x166.png 300w\" sizes=\"(max-width: 581px) 100vw, 581px\" \/><\/a><figcaption id=\"caption-attachment-46852\" class=\"wp-caption-text\">git status &#8211; modified files<\/figcaption><\/figure><\/p>\n<p>Run git add project-plan.txt and hit git status again<\/p>\n<p><figure id=\"attachment_46853\" aria-describedby=\"caption-attachment-46853\" style=\"width: 582px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status4.png\"><img decoding=\"async\" class=\"wp-image-46853 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status4.png\" alt=\"\" width=\"582\" height=\"322\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status4.png 582w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status4-300x166.png 300w\" sizes=\"(max-width: 582px) 100vw, 582px\" \/><\/a><figcaption id=\"caption-attachment-46853\" class=\"wp-caption-text\">git add &#8211; modified files<\/figcaption><\/figure><\/p>\n<p>Suppose you modify any of these file again then you have to stage them again by running git add otherwise the last snapshot will be committed (this can be checked by running git status before a commit which is always a good idea). We have two staged files now which can be committed.<\/p>\n<h3 id=\"ignore\">4.7 Files never to be committed [git ignore]<\/h3>\n<p>Create project.temp file in your local git project directory. This is the file which we want to keep on our local and never want to commit.<\/p>\n<p>Run git status now, you will see an output like this<\/p>\n<p><figure id=\"attachment_46854\" aria-describedby=\"caption-attachment-46854\" style=\"width: 581px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status5.png\"><img decoding=\"async\" class=\"wp-image-46854 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status5.png\" alt=\"\" width=\"581\" height=\"322\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status5.png 581w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status5-300x166.png 300w\" sizes=\"(max-width: 581px) 100vw, 581px\" \/><\/a><figcaption id=\"caption-attachment-46854\" class=\"wp-caption-text\">git status &#8211; untracked files<\/figcaption><\/figure><\/p>\n<p>Git has tracked files and untracked files. There are some files (compiled code files, system generated temp files, build files etc.) which you may not ever want to check-in into the repository and also don&#8217;t want git to show you that they needs to be added.[ulp id=&#8217;pzgfvmZhgslwSymm&#8217;]<\/p>\n<pre class=\"brush:bash\">cat .gitignore\n*_\n*.temp\n<\/pre>\n<p>First line tells git to ignore files ending with an underscore (_). Second line tells git to ignore files with temp extension.<\/p>\n<p><span style=\"text-decoration: underline;\">NOTE:<\/span> Windows don&#8217;t let you create .gitignore file. Manually create gitignore.txt and put ignore patterns there. Open Command window to this location and type ren gitignore.txt .gitignore and you are done.<\/p>\n<p>The rules for the patterns you can put in the .gitignore file are as follows:[1]<\/p>\n<ol>\n<li>Blank lines or lines starting with # are ignored.<\/li>\n<li>Standard glob patterns work.<\/li>\n<li>You can start patterns with a forward slash (\/) to avoid recursivity.<\/li>\n<li>You can end patterns with a forward slash (\/) to specify a directory.<\/li>\n<li>You can negate a pattern by starting it with an exclamation point (!).<\/li>\n<\/ol>\n<h3 id=\"diff\">4.8 What exactly got changed [git diff]<\/h3>\n<p>Currently we have three files; one new addition, one modified and one that we want to ignore. Let&#8217;s run git status<\/p>\n<p><figure id=\"attachment_46855\" aria-describedby=\"caption-attachment-46855\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status6.png\"><img decoding=\"async\" class=\"wp-image-46855 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status6.png\" alt=\"\" width=\"580\" height=\"322\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status6.png 580w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status6-300x167.png 300w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/a><figcaption id=\"caption-attachment-46855\" class=\"wp-caption-text\">git status<\/figcaption><\/figure><\/p>\n<p>If you want to know exactly what you changed, not just which files were changed \u2013 you can use the git diff command. This command compares what is in your working directory with what is in your staging area. The result tells you the changes you\u2019ve made that you haven\u2019t yet staged.<\/p>\n<p>If you want to see what you\u2019ve staged that will go into your next commit, you can use git diff &#8211;staged. This command compares your staged changes to your last commit:<\/p>\n<p><figure id=\"attachment_46856\" aria-describedby=\"caption-attachment-46856\" style=\"width: 578px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status7.png\"><img decoding=\"async\" class=\"wp-image-46856 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status7.png\" alt=\"\" width=\"578\" height=\"320\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status7.png 578w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status7-300x166.png 300w\" sizes=\"(max-width: 578px) 100vw, 578px\" \/><\/a><figcaption id=\"caption-attachment-46856\" class=\"wp-caption-text\">git diff<\/figcaption><\/figure><\/p>\n<blockquote>\n<p>git diff by itself doesn\u2019t show all changes made since your last commit \u2013 only changes that are still unstaged. This can be confusing, because if you\u2019ve staged all of your changes, git diff will give you no output.<\/p>\n<\/blockquote>\n<p>Run git diff &#8211;cached to see what you\u2019ve staged so far.<\/p>\n<p><figure id=\"attachment_46857\" aria-describedby=\"caption-attachment-46857\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status8.png\"><img decoding=\"async\" class=\"wp-image-46857 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status8.png\" alt=\"\" width=\"580\" height=\"321\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status8.png 580w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status8-300x166.png 300w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/a><figcaption id=\"caption-attachment-46857\" class=\"wp-caption-text\">git diff &#8211;cached<\/figcaption><\/figure><\/p>\n<h3 id=\"commit\">4.9 Commit your changes [git commit]<\/h3>\n<p>Remember that anything that is still unstaged \u2013 any files you have created or modified that you haven\u2019t run git add on since you edited them \u2013 won\u2019t go into this commit. Tha&#8217;s why it is always a good idea to run git status before you commit your changes.<\/p>\n<p>To commit your changes run<\/p>\n<p><code>git commit -m &lt;commit_message&gt;<\/code><\/p>\n<pre class=\"brush:bash\">git commit -m \"first commit\"\n<\/pre>\n<blockquote>\n<p>Commit creates a snapshot of the project&#8217;s changes which were staged by using git add command. Anything you didn\u2019t stage is still sitting there modified; you can do another commit to add it to your history. Every time you perform a commit, you\u2019re recording a snapshot of your project that you can revert to or compare to later.<\/p>\n<\/blockquote>\n<p>Run git status again and you will again see a clean workarea.<\/p>\n<p><figure id=\"attachment_46858\" aria-describedby=\"caption-attachment-46858\" style=\"width: 579px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status9.png\"><img decoding=\"async\" class=\"wp-image-46858 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status9.png\" alt=\"\" width=\"579\" height=\"321\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status9.png 579w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status9-300x166.png 300w\" sizes=\"(max-width: 579px) 100vw, 579px\" \/><\/a><figcaption id=\"caption-attachment-46858\" class=\"wp-caption-text\">git commit<\/figcaption><\/figure><\/p>\n<h3 id=\"rm\">4.10 Removing and Deleting tracked files [git rm]<\/h3>\n<p>There are two ways to delete files from your workarea and remove it from staging so that it won&#8217;t be tracked anymore:<\/p>\n<p>1) Run git rm &lt;filename&gt; which will remove the file from being tracked and also from your working area.<br \/>\n2) Delete the file and then run git rm &lt;filename&gt;. Removing the file from your working directory will show the file as changed and not deleted. Hence, it is necessary to run git rm to remove it from being tracked.<\/p>\n<p>Note, you have to run git commit in both the cases so that git stops tracking them.<\/p>\n<p>You can use the same command even when you don&#8217;t want to delete the file but want to untrack it.<\/p>\n<p><code>git rm --cached &lt;filename&gt;<\/code><\/p>\n<h3 id=\"mv\">4.11 Tracking renamed files [git mv]<\/h3>\n<p>If you rename a file, Git would have no idea that it happened. You would have to run git rm old_file and git add new_file. However, with this approach git would lose all the previous history of the old file. Run git mv &lt;old_file&gt; &lt;new_file&gt; to do it correctly. Try it as shown below.<\/p>\n<p><figure id=\"attachment_46859\" aria-describedby=\"caption-attachment-46859\" style=\"width: 579px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status10.png\"><img decoding=\"async\" class=\"wp-image-46859 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status10.png\" alt=\"\" width=\"579\" height=\"319\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status10.png 579w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-status10-300x165.png 300w\" sizes=\"(max-width: 579px) 100vw, 579px\" \/><\/a><figcaption id=\"caption-attachment-46859\" class=\"wp-caption-text\">git mv<\/figcaption><\/figure><\/p>\n<h3 id=\"log\">4.12 Show me the history [git log]<\/h3>\n<p>git log by default shows the commit history in the reverse chronological order. There are variety of options available to filter out the results.<\/p>\n<p>For example, git log -3 will show you last 3 commits only. (git log -&lt;n&gt;). git log &#8211;since=2.weeks will show the commits made in the past 2 weeks.<\/p>\n<p>You can also filter the list to commits that match some search criteria. The &#8211;author option allows you to filter on a specific author, and the &#8211;grep option lets you search for keywords in the commit messages. (Note that if you want to specify both author and grep options, you have to add &#8211;all-match or the command will match commits with either.)<\/p>\n<p><figure id=\"attachment_46870\" aria-describedby=\"caption-attachment-46870\" style=\"width: 587px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-log.png\"><img decoding=\"async\" class=\"wp-image-46870 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-log.png\" alt=\"\" width=\"587\" height=\"622\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-log.png 587w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-log-283x300.png 283w\" sizes=\"(max-width: 587px) 100vw, 587px\" \/><\/a><figcaption id=\"caption-attachment-46870\" class=\"wp-caption-text\">git log<\/figcaption><\/figure><\/p>\n<h3 id=\"remote\">4.13 Show me the remote location [git remote]<\/h3>\n<p>This command shows you from where you have cloned your repository. &#8220;origin&#8221; is the default name Git gives to the server you cloned your repository from.<\/p>\n<p><figure id=\"attachment_46871\" aria-describedby=\"caption-attachment-46871\" style=\"width: 586px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-remote.png\"><img decoding=\"async\" class=\"wp-image-46871 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-remote.png\" alt=\"\" width=\"586\" height=\"253\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-remote.png 586w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-remote-300x130.png 300w\" sizes=\"(max-width: 586px) 100vw, 586px\" \/><\/a><figcaption id=\"caption-attachment-46871\" class=\"wp-caption-text\">git remote<\/figcaption><\/figure><\/p>\n<p>&#8220;-v&#8221; option shows the remote URL of the repository. Notice (fetch) and (pull) against the remote URL. This shows the permission the author has on the repository. Having both means you have write access to the remote repository.<\/p>\n<h3 id=\"fetch\">4.14 &nbsp;Get Remote Data\/Files [git fetch, git pull]<\/h3>\n<p>The syntax is like:<\/p>\n<p><code>git fetch [remote-name]<\/code><\/p>\n<p>The command git fetch automatically adds the remote repository under the name &#8220;origin&#8221;. It&#8217;s the same as git fetch origin.<\/p>\n<p>NOTE: git fetch only downloads the data to your local repository and doesn&#8217;t merge it with any file that has changed locally. The changes have to be merged manually.<\/p>\n<p>Running git pull merges the code as well. Let&#8217;s create a new file remotely on github &#8220;test-fetch.txt&#8221; and run git fetch.<\/p>\n<p><figure id=\"attachment_46872\" aria-describedby=\"caption-attachment-46872\" style=\"width: 586px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-fecth-pull.png\"><img decoding=\"async\" class=\"wp-image-46872 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-fecth-pull.png\" alt=\"\" width=\"586\" height=\"335\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-fecth-pull.png 586w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-fecth-pull-300x172.png 300w\" sizes=\"(max-width: 586px) 100vw, 586px\" \/><\/a><figcaption id=\"caption-attachment-46872\" class=\"wp-caption-text\">git fetch and git pull<\/figcaption><\/figure><\/p>\n<h3 id=\"push\">4.15 Send local changes to remote [git push]<\/h3>\n<blockquote>\n<p>Unless you do a git push, all the changes wether staged or committed happens locally on your machine and remote is not aware of it. Git creates the snapshot for all these changes and you push this snapshot to the remote.<\/p>\n<\/blockquote>\n<p>The command for this is: git push [remote-name] [branch-name]. If you want to push your master branch to your origin server, then you can run this to push any commits you\u2019ve done back up to the server:<\/p>\n<pre class=\"brush:bash\">git push origin master\n<\/pre>\n<p><figure id=\"attachment_46875\" aria-describedby=\"caption-attachment-46875\" style=\"width: 587px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-push.png\"><img decoding=\"async\" class=\"wp-image-46875 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-push.png\" alt=\"\" width=\"587\" height=\"243\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-push.png 587w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/05\/git-push-300x124.png 300w\" sizes=\"(max-width: 587px) 100vw, 587px\" \/><\/a><figcaption id=\"caption-attachment-46875\" class=\"wp-caption-text\">git push<\/figcaption><\/figure><\/p>\n<p>Now all our local changes should be pushed to remote and anyone else tracking our project from remote can pull these changes.<\/p>\n<p>This is how remote repository looked like before pushing the changes:<\/p>\n<p><figure id=\"attachment_46888\" aria-describedby=\"caption-attachment-46888\" style=\"width: 856px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/before.png\"><img decoding=\"async\" class=\"wp-image-46888 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/before.png\" alt=\"\" width=\"856\" height=\"489\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/before.png 856w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/before-300x171.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/before-768x439.png 768w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><figcaption id=\"caption-attachment-46888\" class=\"wp-caption-text\">Remote Repository &#8211; Before pushing the changes<\/figcaption><\/figure><\/p>\n<p>After pushing the changes:<\/p>\n<p><figure id=\"attachment_46887\" aria-describedby=\"caption-attachment-46887\" style=\"width: 859px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/after-push.png\"><img decoding=\"async\" class=\"wp-image-46887 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/after-push.png\" alt=\"\" width=\"859\" height=\"519\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/after-push.png 859w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/after-push-300x181.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/after-push-768x464.png 768w\" sizes=\"(max-width: 859px) 100vw, 859px\" \/><\/a><figcaption id=\"caption-attachment-46887\" class=\"wp-caption-text\">Remote Repository &#8211; After pushing the changes<\/figcaption><\/figure><\/p>\n<p>NOTE: git push command will only work if you have write access on remote. Also, if there are changes on the remote that you don&#8217;t have locally, you would have to pull them first before pushing yours.<\/p>\n<h2 id=\"summary\">5. Summary<\/h2>\n<p>Here is a list of all the commands we learnt in this tutorial. Git has a very long list of commands. Here we have learnt the most important ones that can easily get you started with Git.<\/p>\n<ol>\n<li>Initial Git Configuration [<a href=\"#config\">git config<\/a>]<\/li>\n<li>Asking Git for help [<a href=\"#help\">git help<\/a>]<\/li>\n<li>Creating a new repository [<a href=\"#init\">git init<\/a>]<\/li>\n<li>Checking out existing repository [<a href=\"#clone\">git clone<\/a>]<\/li>\n<li>Check the status of your project [<a href=\"#status\">git status<\/a>]<\/li>\n<li>Start tracking new files [<a href=\"#add\">git add<\/a>]<\/li>\n<li>Files never to be committed [<a href=\"#ignore\">git ignore<\/a>]<\/li>\n<li>What exactly got changed [<a href=\"#diff\">git diff<\/a>]<\/li>\n<li>Commit your changes [<a href=\"#commit\">git commit<\/a>]<\/li>\n<li>Removing and Deleting tracked files [<a href=\"#rm\">git rm<\/a>]<\/li>\n<li>Tracking renamed files [<a href=\"#mv\">git mv<\/a>]<\/li>\n<li>Show me the history [<a href=\"#log\">git log<\/a>]<\/li>\n<li>Show me the remote location [<a href=\"#remote\">git remote<\/a>]<\/li>\n<li>Get Remote Data\/Files [<a href=\"#fetch\">git fetch, git pull<\/a>]<\/li>\n<li>Send local changes to remote [<a href=\"#push\">git push<\/a>]<\/li>\n<\/ol>\n<h2 id=\"references\">6. References<\/h2>\n<ol>\n<li><a href=\"https:\/\/git-scm.com\/book\/en\/v2\/Getting-Started-About-Version-Control\">https:\/\/git-scm.com\/book\/en\/v2\/Getting-Started-About-Version-Control<\/a><\/li>\n<li><a href=\"https:\/\/git-scm.com\/book\/en\/v2\/Getting-Started-Installing-Git\">https:\/\/git-scm.com\/book\/en\/v2\/Getting-Started-Installing-Git<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>If you are a software developer, there is a pretty good chance that you must have used version control software in one form or the other. Git has surged in popularity over the past few years&nbsp;succeeding SVN and CVS. With almost every open source project migrated to Git as a version control of choice, it &hellip;<\/p>\n","protected":false},"author":116,"featured_media":27377,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1353],"tags":[],"class_list":["post-45221","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-git"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Git Commands Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"If you are a software developer, there is a pretty good chance that you must have used version control software in one form or the other. Git has surged\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Git Commands Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"If you are a software developer, there is a pretty good chance that you must have used version control software in one form or the other. Git has surged\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/mayankbindaas\" \/>\n<meta property=\"article:published_time\" content=\"2017-06-02T08:00:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-23T11:23:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/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=\"Mayank Gupta\" \/>\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=\"Mayank Gupta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/\"},\"author\":{\"name\":\"Mayank Gupta\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5c462e68d6e7410cd4f83202b7ed8d50\"},\"headline\":\"Git Commands Tutorial\",\"datePublished\":\"2017-06-02T08:00:42+00:00\",\"dateModified\":\"2019-04-23T11:23:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/\"},\"wordCount\":3503,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg\",\"articleSection\":[\"Git\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/\",\"name\":\"Git Commands Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg\",\"datePublished\":\"2017-06-02T08:00:42+00:00\",\"dateModified\":\"2019-04-23T11:23:07+00:00\",\"description\":\"If you are a software developer, there is a pretty good chance that you must have used version control software in one form or the other. Git has surged\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Software Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/software-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Git\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/software-development\/git\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Git Commands Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5c462e68d6e7410cd4f83202b7ed8d50\",\"name\":\"Mayank Gupta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/03\/Mayank-Gupta-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/03\/Mayank-Gupta-96x96.jpg\",\"caption\":\"Mayank Gupta\"},\"description\":\"Senior JEE developer with experience in large scale IT projects, especially in the telecommunications and financial services sectors. Mayank has been designing and building J2EE applications since 2007. Fascinated by all forms of software development; keen to explore upcoming areas of technology like AI, machine learning, blockchain development and AR. Lover of gadgets, apps, technology and gaming.\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\",\"https:\/\/www.facebook.com\/mayankbindaas\",\"https:\/\/www.linkedin.com\/in\/mayankbindas\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/mayank-gupta\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Git Commands Tutorial - Java Code Geeks","description":"If you are a software developer, there is a pretty good chance that you must have used version control software in one form or the other. Git has surged","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:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Git Commands Tutorial - Java Code Geeks","og_description":"If you are a software developer, there is a pretty good chance that you must have used version control software in one form or the other. Git has surged","og_url":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/mayankbindaas","article_published_time":"2017-06-02T08:00:42+00:00","article_modified_time":"2019-04-23T11:23:07+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg","type":"image\/jpeg"}],"author":"Mayank Gupta","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Mayank Gupta","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/"},"author":{"name":"Mayank Gupta","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5c462e68d6e7410cd4f83202b7ed8d50"},"headline":"Git Commands Tutorial","datePublished":"2017-06-02T08:00:42+00:00","dateModified":"2019-04-23T11:23:07+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/"},"wordCount":3503,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg","articleSection":["Git"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/","url":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/","name":"Git Commands Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg","datePublished":"2017-06-02T08:00:42+00:00","dateModified":"2019-04-23T11:23:07+00:00","description":"If you are a software developer, there is a pretty good chance that you must have used version control software in one form or the other. Git has surged","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/git-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/git\/git-commands-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Software Development","item":"https:\/\/examples.javacodegeeks.com\/category\/software-development\/"},{"@type":"ListItem","position":3,"name":"Git","item":"https:\/\/examples.javacodegeeks.com\/category\/software-development\/git\/"},{"@type":"ListItem","position":4,"name":"Git Commands Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5c462e68d6e7410cd4f83202b7ed8d50","name":"Mayank Gupta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/03\/Mayank-Gupta-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/03\/Mayank-Gupta-96x96.jpg","caption":"Mayank Gupta"},"description":"Senior JEE developer with experience in large scale IT projects, especially in the telecommunications and financial services sectors. Mayank has been designing and building J2EE applications since 2007. Fascinated by all forms of software development; keen to explore upcoming areas of technology like AI, machine learning, blockchain development and AR. Lover of gadgets, apps, technology and gaming.","sameAs":["https:\/\/www.javacodegeeks.com","https:\/\/www.facebook.com\/mayankbindaas","https:\/\/www.linkedin.com\/in\/mayankbindas"],"url":"https:\/\/examples.javacodegeeks.com\/author\/mayank-gupta\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/45221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/116"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=45221"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/45221\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/27377"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=45221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=45221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=45221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}