{"id":12250,"date":"2013-05-02T13:00:32","date_gmt":"2013-05-02T10:00:32","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=12250"},"modified":"2013-05-02T08:24:33","modified_gmt":"2013-05-02T05:24:33","slug":"git-explained-for-beginners","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-for-beginners.html","title":{"rendered":"Git Explained: For Beginners"},"content":{"rendered":"<p>I\u2019m working with Git now <a href=\"\/blog\/2010\/11\/juri-goes-git-first-steps\/\">for about two years<\/a> but only for my personal projects and those I have on GitHub. At work we still use TFS and SVN (as of now). Recently <a href=\"https:\/\/twitter.com\/nusco\">Paolo Perrotta<\/a> came to our company to hold a course about Agile planning and since Git was quite new to most of my mates, he also quickly explained Git in the context of refactoring. I really liked his approach of explaining it and that\u2019s why I\u2019d like to replicate his explanation here.<\/p>\n<h2>Just before we start..<\/h2>\n<p>How is Git different from other VCS (Version Control Systems)? Probably the most obvious difference is that Git is distributed (unlike SVN or TFS for instance). This<br \/>\n&nbsp;<br \/>\nmeans, you\u2019ll have a local repository which lives inside a special folder named <code>.git<\/code> and you\u2019ll normally (but not necessarily) have a remote, central repository where different collaborators may contribute their code. Note that each of those contributors has an <strong>exact clone<\/strong> of the repository on their local workstation.<\/p>\n<p>Git itself can be imagined as something that sits on top of your file system and manipulates files. Even better, you can imagine Git as a <strong>tree<\/strong> structure where <strong>each commit creates a new node<\/strong> in that tree. Nearly all Git commands actually serve to navigate on this tree and to manipulate it accordingly. As such in this tutorial I\u2019d like to take a look at how Git works by viewing a Git repository from the point of view of the tree it constructs. To do so I walk through some common use cases like<\/p>\n<ul>\n<li>adding\/modifying a new file<\/li>\n<li>creating and merging a branch with and without merge conflicts<\/li>\n<li>Viewing the history\/changelog<\/li>\n<li>Performing a rollback to a certain commit<\/li>\n<li>Sharing\/synching your code to a remote\/central repository<\/li>\n<\/ul>\n<h2>Terminology<\/h2>\n<p>Here\u2019s the git terminology:<\/p>\n<ul>\n<li><strong>master &#8211;<\/strong> the repository\u2019s main branch. Depending on the work flow it is the one people work on or the one where the integration happens<\/li>\n<li><strong>clone &#8211;<\/strong> copies an existing git repository, normally from some remote location to your local environment.<\/li>\n<li><strong>commit &#8211;<\/strong> submitting files to the repository (the local one); in other VCS it is often referred to as \u201ccheckin\u201d<\/li>\n<li><strong>fetch or pull &#8211;<\/strong> is like \u201cupdate\u201d or \u201cget latest\u201d in other VCS. The difference between fetch and pull is that pull combines both, fetching the latest code from a remote repo as well as performs the merging.<\/li>\n<li><strong>push &#8211;<\/strong> is used to submit the code to a remote repository<\/li>\n<li><strong>remote &#8211;<\/strong> these are \u201cremote\u201d locations of your repository, normally on some central server.<\/li>\n<li><strong>SHA &#8211;<\/strong> every commit or node in the Git tree is identified by a unique SHA key. You can use them in various commands in order to manipulate a specific node.<\/li>\n<li><strong>head &#8211;<\/strong> is a reference to the node to which our working space of the repository currently points.<\/li>\n<li><strong>branch &#8211;<\/strong> is just like in other VCS with the difference that a branch in Git is actually nothing more special than a particular label on a given node. It is not a physical copy of the files as in other popular VCS.<\/li>\n<\/ul>\n<h2>Workstation Setup<\/h2>\n<p>I do not want to go into the details of setting up your workstation as there are numerous tools which partly vary on the different platforms. For this post I perform all of the operations on the command line. Even if you\u2019re not the shell-guy you should give it a try (it never hurts). To setup command line Git access simply go to <a href=\"http:\/\/git-scm.com\/downloads\">git-scm.com\/downloads<\/a> where you\u2019ll find the required downloads for your OS. More detailed information can be found <a href=\"http:\/\/git-scm.com\/book\/en\/Getting-Started-Installing-Git\">here as well<\/a>. After everything is set up and you have \u201cgit\u201d in your PATH environment variable, then the first thing you have to do is to config git with your name and email:<\/p>\n<pre class=\" brush:java\">$ git config --global user.name \"Juri Strumpflohner\"\r\n$ git config --global user.email \"myemail@gmail.com\"<\/pre>\n<h2>Lets get started: Create a new Git Repository<\/h2>\n<p>Before starting, lets create a new directory where the git repository will live and <code>cd<\/code> into it:<\/p>\n<pre class=\" brush:java\">$ mkdir mygitrepo\r\n$ cd mygitrepo<\/pre>\n<p>Now we\u2019re ready to initialize a brand new git repository.<\/p>\n<pre class=\" brush:java\">$ git init\r\nInitialized empty Git repository in c:\/projects\/mystuff\/temprepos\/mygitrepo\/.git\/<\/pre>\n<p>We can check for the current status of the git repository by using<\/p>\n<pre class=\" brush:java\">$ git status\r\n# On branch master\r\n#\r\n# Initial commit\r\n#\r\nnothing to commit (create\/copy files and use \"git add\" to track)<\/pre>\n<h2>Create and commit a new file<\/h2>\n<p>The next step is to create a new file and add some content to it.<\/p>\n<pre class=\" brush:java\">$ touch hallo.txt\r\n$ echo Hello, world! &gt; hallo.txt<\/pre>\n<p>Again, checking for the status now reveals the following<\/p>\n<pre class=\" brush:java\">$ git status\r\n# On branch master\r\n#\r\n# Initial commit\r\n#\r\n# Untracked files:\r\n#   (use \"git add &lt;file&gt;...\" to include in what will be committed)\r\n#\r\n#       hallo.txt\r\nnothing added to commit but untracked files present (use \"git add\" to track)<\/pre>\n<p>To <strong>\u201cregister\u201d<\/strong> the file for committing we need to <strong>add<\/strong> it to git using<\/p>\n<pre class=\" brush:java\">$ git add hallo.txt<\/pre>\n<p>Checking for the status now indicates that the file is ready to be committed:<\/p>\n<pre class=\" brush:java\">$ git status\r\n# On branch master\r\n#\r\n# Initial commit\r\n#\r\n# Changes to be committed:\r\n#   (use \"git rm --cached &lt;file&gt;...\" to unstage)\r\n#\r\n#       new file:   hallo.txt\r\n#<\/pre>\n<p>We can now <strong>commit<\/strong> it to the repository<\/p>\n<pre class=\" brush:java\">$ git commit -m \"Add my first file\"\r\n  1 file changed, 1 insertion(+)\r\n  create mode 100644 hallo.txt<\/pre>\n<p>It is common practice to use the \u201cpresence\u201d in commit messages. So rather than writing \u201cadded my first file\u201d we write \u201cadd my first file\u201d. So if we now step back for a second and take a look at the tree we would have the following.<br \/>\n<figure id=\"attachment_12290\" aria-describedby=\"caption-attachment-12290\" style=\"width: 201px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree1.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree1.png\" alt=\"State of the repo tree after 1st commit\" width=\"201\" height=\"29\" class=\"size-full wp-image-12290\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree1.png 201w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree1-200x29.png 200w\" sizes=\"(max-width: 201px) 100vw, 201px\" \/><\/a><figcaption id=\"caption-attachment-12290\" class=\"wp-caption-text\">State of the repo tree after 1st commit<\/figcaption><\/figure><br \/>\nThere is <em>one node<\/em> where the \u201clabel\u201d <em>master<\/em> points to.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2>Add another file<\/h2>\n<p>Lets add another file:<\/p>\n<pre class=\" brush:java\">$ echo \"Hi, I'm another file\" &gt; anotherfile.txt\r\n$ git add .\r\n$ git commit -m \"add another file with some other content\"\r\n  1 file changed, 1 insertion(+)\r\n  create mode 100644 anotherfile.txt<\/pre>\n<p>Btw, note that this time I used <code>git add .<\/code> which adds all files in the current directory (<code>.<\/code>). From the point of view of the tree we now have another node and master has moved on to that one.<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree2.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree2-300x47.png\" alt=\"gitrepo_tree2\" width=\"300\" height=\"47\" class=\"aligncenter size-medium wp-image-12291\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree2-300x47.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree2.png 340w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h2>Create a (feature)branch<\/h2>\n<p>Branching and merging is what makes Git so powerful and for what it has been optimized, being a distributed version control system (VCS). Indeed, <strong>feature branches<\/strong> are quite popular to be used with Git. Feature branches are created for every new kind of functionality you\u2019re going to add to your system and they are normally deleted afterwards once the feature is merged back into the main integration branch (normally the master branch). The advantage is that you can experiment with new functionality in a separated, isolated \u201cplayground\u201d and quickly switch back and forth to the original \u201cmaster\u201d branch when needed. Moreover, it can be easily discarded again (in case it is not needed) by simply dropping the feature branch. But lets get started. First of all I create the new feature branch:<\/p>\n<pre class=\" brush:java\">$ git branch my-feature-branch<\/pre>\n<p>Executing<\/p>\n<pre class=\" brush:java\">$ git branch\r\n* master\r\n  my-feature-branch<\/pre>\n<p>we get a list of branches. The <code>*<\/code> in front of <code>master<\/code> indicates that we\u2019re currently on that branch. Lets switch to <code>my-feature-branch<\/code> instead:<\/p>\n<pre class=\" brush:java\">$ git checkout my-feature-branch\r\nSwitched to branch 'my-feature-branch'<\/pre>\n<p>Again<\/p>\n<pre class=\" brush:java\">$ git branch\r\n  master\r\n* my-feature-branch<\/pre>\n<p>Note you can directly use the command <code>git checkout -b my-feature-branch<\/code> to <em>create<\/em> and <em>checkout<\/em> a new branch in one step. What\u2019s different to other VCS is that there is only <em>one working directory<\/em>. All of your branches live in the same one and there is not a separate folder for each branch you create. Instead, when you switch between branches, Git will replace the content of your working directory to reflect the one in the branch you\u2019re switching to. Lets modify one of our existing files<\/p>\n<pre class=\" brush:java\">$ echo \"Hi\" &gt;&gt; hallo.txt\r\n$ cat hallo.txt\r\nHello, world!\r\nHi<\/pre>\n<p>\u2026and then commit it to our new branch<\/p>\n<pre class=\" brush:java\">$ git commit -a -m \"modify file adding hi\"\r\n2fa266a] modify file adding hi\r\n1 file changed, 1 insertion(+)<\/pre>\n<p><strong>Note<\/strong>, this time I used the <code>git commit -a -m<\/code> to add and commit a modification in one step. This works only on files that have already been added to the git repo before. New files won\u2019t be added this way and need an explicit <code>git add<\/code> as seen before. What about our tree?<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree3.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree3-300x61.png\" alt=\"gitrepo_tree3\" width=\"300\" height=\"61\" class=\"aligncenter size-medium wp-image-12292\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree3-300x61.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree3.png 328w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>So far everything seems pretty normal and we still have a straight line in the tree, but note that now <code>master<\/code> remained where it was and we moved forward with <code>my-feature-branch<\/code>. Lets switch back to master and modify the same file there as well.<\/p>\n<pre class=\" brush:java\">$ git checkout master\r\nSwitched to branch 'master'<\/pre>\n<p>As expected, <code>hallo.txt<\/code> is unmodified:<\/p>\n<pre class=\" brush:java\">$ cat hallo.txt\r\nHello, world!<\/pre>\n<p>Lets change and commit it on master as well (this will generate a nice <em>conflict<\/em> later).<\/p>\n<pre class=\" brush:java\">$ echo \"Hi I was changed in master\" &gt;&gt; hallo.txt\r\n$ git commit -a -m \"add line on hallo.txt\"\r\nc8616db] add line on hallo.txt\r\n1 file changed, 1 insertion(+)<\/pre>\n<p>Our tree now visualizes the branch:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree4.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree4-300x77.png\" alt=\"gitrepo_tree4\" width=\"300\" height=\"77\" class=\"aligncenter size-medium wp-image-12293\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree4-300x77.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree4.png 301w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h2>Merge and resolve conflicts<\/h2>\n<p>The next step would be to merge our feature branch back into <code>master<\/code>. This is done by using the merge command<\/p>\n<pre class=\" brush:java\">$ git merge my-feature-branch\r\nAuto-merging hallo.txt\r\nCONFLICT (content): Merge conflict in hallo.txt\r\nAutomatic merge failed; fix conflicts and then commit the result.<\/pre>\n<p>As expected, we have a merge conflict in <code>hallo.txt<\/code>.<\/p>\n<pre class=\" brush:java\">Hello, world!\r\n&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD\r\nHi I was changed in master\r\n=======\r\nHi\r\n&gt;&gt;&gt;&gt;&gt;&gt;&gt; my-feature-branch<\/pre>\n<p>Lets resolve it:<\/p>\n<pre class=\" brush:java\">Hello, world!\r\nHi I was changed in master\r\nHi<\/pre>\n<p>..and then commit it<\/p>\n<pre class=\" brush:java\">$ git commit -a -m \"resolve merge conflicts\"\r\n[master 6834fb2] resolve merge conflicts<\/pre>\n<p>The tree reflects our merge.<\/p>\n<h2>Jump to a certain commit<\/h2>\n<p>Lets assume we want to jump back to a given commit. We can use the <code>git log<\/code> command to get all the SHA identifiers that uniquely identify each node in the tree.<\/p>\n<pre class=\" brush:java\">$ git log\r\ncommit 6834fb2b38d4ed12f5486ebcb6c1699fe9039e8e\r\nMerge: c8616db 2fa266a\r\nAuthor: = &lt;juri.strumpflohner@gmail.com&gt;\r\nDate:   Mon Apr 22 23:19:32 2013 +0200\r\n\r\n    resolve merge conflicts\r\n\r\ncommit c8616db8097e926c64bfcac4a09306839b008dc6\r\nAuthor: Juri &lt;juri.strumpflohner@gmail.com&gt;\r\nDate:   Mon Apr 22 09:39:57 2013 +0200\r\n\r\n    add line on hallo.txt\r\n\r\ncommit 2fa266aaaa61c51bd77334516139597a727d4af1\r\nAuthor: Juri &lt;juri.strumpflohner@gmail.com&gt;\r\nDate:   Mon Apr 22 09:24:00 2013 +0200\r\n\r\n    modify file adding hi\r\n\r\ncommit 03883808a04a268309b9b9f5c7ace651fc4f3f4b\r\nAuthor: Juri &lt;juri.strumpflohner@gmail.com&gt;\r\nDate:   Mon Apr 22 09:13:49 2013 +0200\r\n\r\n    add another file with some other content\r\n\r\ncommit aad15dea687e46e9104db55103919d21e9be8916\r\nAuthor: Juri &lt;juri.strumpflohner@gmail.com&gt;\r\nDate:   Mon Apr 22 08:58:51 2013 +0200\r\n\r\n    Add my first file<\/pre>\n<p>Take one of the identifiers (also if it isn\u2019t the whole one, it doesn\u2019t matter) and jump to that node by using the <code>checkout<\/code> command<\/p>\n<pre class=\" brush:java\">$ git checkout c8616db\r\nNote: checking out 'c8616db'.\r\n\r\nYou are in 'detached HEAD' state. You can look around, make experimental\r\nchanges and commit them, and you can discard any commits you make in this\r\nstate without impacting any branches by performing another checkout.\r\n\r\nIf you want to create a new branch to retain commits you create, you may\r\ndo so (now or later) by using -b with the checkout command again. Example:\r\n\r\n  git checkout -b new_branch_name\r\n\r\nHEAD is now at c8616db... add line on hallo.txt<\/pre>\n<p>Note the comment git prints out. What does that mean? <strong>Detached head<\/strong> means \u201chead\u201d is no more pointing to a branch \u201clabel\u201d but instead to a specific commit in the tree. You can think of the <strong>HEAD<\/strong> as the \u201ccurrent branch\u201d. When you switch branches with <code>git checkout<\/code>, the HEAD revision changes to point to the tip of the new branch. \u2026 It is possible for HEAD to refer to a specific revision that is not associated with a branch name. This situation is called a <a href=\"http:\/\/git-scm.com\/docs\/git-checkout#_detached_head\">detached HEAD<\/a>. <cite><a href=\"http:\/\/stackoverflow.com\/a\/2304106\/50109\">Stackoverflow Post<\/a><\/cite> Basically when I now change hallo.txt and commit the change, the tree looks as follows:<br \/>\n<figure id=\"attachment_12295\" aria-describedby=\"caption-attachment-12295\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree6.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree6-300x98.png\" alt=\"Detached head state\" width=\"300\" height=\"98\" class=\"size-medium wp-image-12295\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree6-300x98.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree6.png 352w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-12295\" class=\"wp-caption-text\">Detached head state<\/figcaption><\/figure><br \/>\nAs you can see, the newly created node has no label on it. The only reference that currently points towards it is <code>head<\/code>. However, if we now switch to master again then the previous commit will be lost as we have no way of jumping back to that tree node.<\/p>\n<pre class=\" brush:java\">$ git checkout master\r\nWarning: you are leaving 1 commit behind, not connected to\r\nany of your branches:\r\n\r\n  576bcb8 change file undoing previous changes\r\n\r\nIf you want to keep them by creating a new branch, this may be a good time\r\nto do so with:\r\n\r\n git branch new_branch_name 576bcb8239e0ef49d3a6d5a227ff2d1eb73eee55\r\n\r\nSwitched to branch 'master'<\/pre>\n<p>And in fact, git is so kind to remind us about this fact. The tree looks now again as in figure 6.<\/p>\n<h2>Rollback<\/h2>\n<p>Jumping back is nice, but what if we want to <strong>undo<\/strong> everything back to the state before the merge of the feature branch? It is as easy as<\/p>\n<pre class=\" brush:java\">$ git reset --hard c8616db\r\nHEAD is now at c8616db add line on hallo.txt<\/pre>\n<p><figure id=\"attachment_12296\" aria-describedby=\"caption-attachment-12296\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree41.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree41-300x77.png\" alt=\"The tree after the reset\" width=\"300\" height=\"77\" class=\"size-medium wp-image-12296\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree41-300x77.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/05\/gitrepo_tree41.png 301w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-12296\" class=\"wp-caption-text\">The tree after the reset<\/figcaption><\/figure><br \/>\nThe generic syntax here is <code>git reset --hard &lt;tag\/branch\/commit id&gt;<\/code>.<\/p>\n<h2>Sharing\/Synching your Repository<\/h2>\n<p>Ultimately we want to share our code, normally by synching it to a central repository. For doing so, we have to add a <strong>remote<\/strong>.<\/p>\n<pre class=\" brush:java\">$ git remote add origin git@github.com:juristr\/intro.js.git<\/pre>\n<p>To see whether I succeeded, simply type:<\/p>\n<pre class=\" brush:java\">$ git remote -v<\/pre>\n<p>which lists all of the added remotes. Now we need to <strong>publish our local branch master<\/strong> to the remote repository. This is done like<\/p>\n<pre class=\" brush:java\">$ git push -u origin master<\/pre>\n<p>And we\u2019re done. The real powerful thing is that you can add multiple different remotes. This is often used in combination with cloud hosting solutions for deploying your code on your server. For instance, you could add a remote named \u201cdeploy\u201d which points to some cloud hosting server repository, like<\/p>\n<pre class=\" brush:java\">$ git remote add deploy git@somecloudserver.com:juristr\/myproject<\/pre>\n<p>and then whenever you want to publish your branch you execute a<\/p>\n<pre class=\" brush:java\">$ git push deploy<\/pre>\n<h4>Cloning<\/h4>\n<p>Similarly it works if you\u2019d like to start from an existing remote repository. The first step that needs to be done is to \u201ccheckout\u201d the source code which is called <strong>cloning<\/strong> in Git terminology. So we would do something like<\/p>\n<pre class=\" brush:java\">$ git clone git@github.com:juristr\/intro.js.git\r\nCloning into 'intro.js'...\r\nremote: Counting objects: 430, done.\r\nremote: Compressing objects: 100% (293\/293), done.\r\nremote: Total 430 (delta 184), reused 363 (delta 128)\r\nReceiving objects: 100% (430\/430), 419.70 KiB | 102 KiB\/s, done.\r\nResolving deltas: 100% (184\/184), done.<\/pre>\n<p>This will create a folder (in this case) named \u201cintro.js\u201d and if we enter it<\/p>\n<pre class=\" brush:java\">$ cd intro.js\/<\/pre>\n<p>and check for the remotes we see that the according tracking information of the remote repository is already set up<\/p>\n<pre class=\" brush:java\">$ git remote -v\r\norigin  git@github.com:juristr\/intro.js.git (fetch)\r\norigin  git@github.com:juristr\/intro.js.git (push)<\/pre>\n<p>We can now start the commit\/branch\/push cycle just normally.<\/p>\n<h2>Resources and Links<\/h2>\n<p>The scenarios above were the simples, but at the same time probably also the most used ones. But there\u2019s a lot more Git is capable of. To get more details you may want to consult the links below.<\/p>\n<ul>\n<li><a href=\"http:\/\/gitready.com\/\">http:\/\/gitready.com\/<\/a><\/li>\n<li><a href=\"http:\/\/git-scm.com\/book\">Book: Pro Git by Scott Chacon<\/a><\/li>\n<li><a href=\"http:\/\/try.github.io\/\">Try Git in 15 minutes<\/a><\/li>\n<li><a href=\"http:\/\/www.youtube.com\/watch?v=ZDR433b0HJY&amp;feature=youtu.be&amp;t=21m4s\">Introduction to Git with Scott Chacon of GitHub<\/a><\/li>\n<li><a href=\"https:\/\/gist.github.com\/juristr\/5280366\">My personal Git Cheat Sheet where I continuously add stuff I want to remember<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<div style=\"border: 1px solid #D8D8D8; background: #FAFAFA; width: 100%; padding-left: 5px;\"><b><i>Reference: <\/i><\/b><a href=\"http:\/\/juristr.com\/blog\/2013\/04\/git-explained\/\">Git Explained: For Beginners <\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Juri Strumpflohner at the <a href=\"http:\/\/juristr.com\/blog\/\">Juri Strumpflohner&#8217;s TechBlog<\/a> blog.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019m working with Git now for about two years but only for my personal projects and those I have on GitHub. At work we still use TFS and SVN (as of now). Recently Paolo Perrotta came to our company to hold a course about Agile planning and since Git was quite new to most of &hellip;<\/p>\n","protected":false},"author":31,"featured_media":118,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[334],"class_list":["post-12250","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-development","tag-git"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Git Explained: For Beginners<\/title>\n<meta name=\"description\" content=\"I\u2019m working with Git now for about two years but only for my personal projects and those I have on GitHub. At work we still use TFS and SVN (as of now).\" \/>\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\/2013\/05\/git-explained-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 Explained: For Beginners\" \/>\n<meta property=\"og:description\" content=\"I\u2019m working with Git now for about two years but only for my personal projects and those I have on GitHub. At work we still use TFS and SVN (as of now).\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-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=\"2013-05-02T10:00:32+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=\"Juri Strumpflohner\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@http:\/\/twitter.com\/juristr\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Juri Strumpflohner\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/git-explained-for-beginners.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/git-explained-for-beginners.html\"},\"author\":{\"name\":\"Juri Strumpflohner\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/90c2d02d13e2a964f7b84146149e0112\"},\"headline\":\"Git Explained: For Beginners\",\"datePublished\":\"2013-05-02T10:00:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/git-explained-for-beginners.html\"},\"wordCount\":1888,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/git-explained-for-beginners.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/git-logo.jpg\",\"keywords\":[\"Git\"],\"articleSection\":[\"Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/git-explained-for-beginners.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/git-explained-for-beginners.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/git-explained-for-beginners.html\",\"name\":\"Git Explained: For Beginners\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/git-explained-for-beginners.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/git-explained-for-beginners.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/git-logo.jpg\",\"datePublished\":\"2013-05-02T10:00:32+00:00\",\"description\":\"I\u2019m working with Git now for about two years but only for my personal projects and those I have on GitHub. At work we still use TFS and SVN (as of now).\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/git-explained-for-beginners.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/git-explained-for-beginners.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/git-explained-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\\\/2013\\\/05\\\/git-explained-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 Explained: 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\\\/90c2d02d13e2a964f7b84146149e0112\",\"name\":\"Juri Strumpflohner\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/45338315375849845e4c4b30f52cb417221e2d9a7e688785e4dd2af0e624a260?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/45338315375849845e4c4b30f52cb417221e2d9a7e688785e4dd2af0e624a260?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/45338315375849845e4c4b30f52cb417221e2d9a7e688785e4dd2af0e624a260?s=96&d=mm&r=g\",\"caption\":\"Juri Strumpflohner\"},\"description\":\"Juri Strumpflohner mainly operates in the web sector developing rich applications with HTML5 and JavaScript. Beside having a Java background and developing Android applications he currently works as a software architect in the e-government sector. When he\u2019s not coding or blogging about his newest discoveries, he is practicing Yoseikan Budo where he owns a 2nd DAN.\",\"sameAs\":[\"http:\\\/\\\/juristr.com\\\/blog\",\"http:\\\/\\\/linkedin.com\\\/in\\\/juristr\\\/\",\"https:\\\/\\\/x.com\\\/http:\\\/\\\/twitter.com\\\/juristr\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Juri-Strumpflohner\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Git Explained: For Beginners","description":"I\u2019m working with Git now for about two years but only for my personal projects and those I have on GitHub. At work we still use TFS and SVN (as of now).","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\/2013\/05\/git-explained-for-beginners.html","og_locale":"en_US","og_type":"article","og_title":"Git Explained: For Beginners","og_description":"I\u2019m working with Git now for about two years but only for my personal projects and those I have on GitHub. At work we still use TFS and SVN (as of now).","og_url":"https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-for-beginners.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-05-02T10:00:32+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":"Juri Strumpflohner","twitter_card":"summary_large_image","twitter_creator":"@http:\/\/twitter.com\/juristr","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Juri Strumpflohner","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-for-beginners.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-for-beginners.html"},"author":{"name":"Juri Strumpflohner","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/90c2d02d13e2a964f7b84146149e0112"},"headline":"Git Explained: For Beginners","datePublished":"2013-05-02T10:00:32+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-for-beginners.html"},"wordCount":1888,"commentCount":3,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-for-beginners.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/git-logo.jpg","keywords":["Git"],"articleSection":["Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-for-beginners.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-for-beginners.html","url":"https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-for-beginners.html","name":"Git Explained: For Beginners","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-for-beginners.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-for-beginners.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/git-logo.jpg","datePublished":"2013-05-02T10:00:32+00:00","description":"I\u2019m working with Git now for about two years but only for my personal projects and those I have on GitHub. At work we still use TFS and SVN (as of now).","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-for-beginners.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-for-beginners.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/git-explained-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\/2013\/05\/git-explained-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 Explained: 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\/90c2d02d13e2a964f7b84146149e0112","name":"Juri Strumpflohner","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/45338315375849845e4c4b30f52cb417221e2d9a7e688785e4dd2af0e624a260?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/45338315375849845e4c4b30f52cb417221e2d9a7e688785e4dd2af0e624a260?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/45338315375849845e4c4b30f52cb417221e2d9a7e688785e4dd2af0e624a260?s=96&d=mm&r=g","caption":"Juri Strumpflohner"},"description":"Juri Strumpflohner mainly operates in the web sector developing rich applications with HTML5 and JavaScript. Beside having a Java background and developing Android applications he currently works as a software architect in the e-government sector. When he\u2019s not coding or blogging about his newest discoveries, he is practicing Yoseikan Budo where he owns a 2nd DAN.","sameAs":["http:\/\/juristr.com\/blog","http:\/\/linkedin.com\/in\/juristr\/","https:\/\/x.com\/http:\/\/twitter.com\/juristr"],"url":"https:\/\/www.javacodegeeks.com\/author\/Juri-Strumpflohner"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/12250","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\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=12250"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/12250\/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=12250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=12250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=12250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}