{"componentChunkName":"component---src-templates-blog-post-js","path":"/using-git-in-cmd","result":{"data":{"markdownRemark":{"html":"<p>Git is a powerful version control system that can be used to easily manage everything from small to large projects.\nHowever, newbies often find using Git a bit challenging. Here's the simple guide to using Git on Windows command line.</p>\n<p><img src=\"https://user-images.githubusercontent.com/10103699/132891938-16fdb62e-5cf3-4a31-a5d0-a3f03452bc3d.jpeg\" alt=\"git1\"></p>\n<p>For those who wonder about the difference between Git and GitHub, GitHub is a Git repository hosting service that\nhas features of Git as well as its own features. Git is a command line tool, whereas GitHub provides a web based\ngraphical user interface (GUI) for using Git repositories.</p>\n<p><img src=\"https://user-images.githubusercontent.com/10103699/132891952-6d342ba0-851d-44b0-846a-e9dbc90cfa04.png\" alt=\"git2\"></p>\n<p>This post assumes that you have Git set up in your computer as well as a GitHub account.</p>\n<p>You can get a Git project using two approaches; either by creating a new repository or cloning an existing one\n(created by someone else) to your machine. The two ways are described below.</p>\n<h3>Creating a new repository</h3>\n<h4>1. Create a Git repository</h4>\n<p> A repository is a special data structure Git uses to store the snapshots of the project you save. This is different\nfrom the project folder you have in your computer. Go to your Git account on GitHub and create a Git repository.</p>\n<p><img src=\"https://user-images.githubusercontent.com/10103699/132892323-a2e6b318-b991-497d-afbb-555ee91831c3.png\" alt=\"git3\"></p>\n<p>Add a repository name that is easy to remember. GitHub will direct you to the page of your newly created repository.</p>\n<h4>2. Initialize your Git repository in your computer.</h4>\n<p>Go to the folder you want to create your project. If you have a project already created, go in to the project folder.\nS<strong>hift+right click</strong> and select <strong>Open command window here</strong> option to get the command line.</p>\n<p>Use <code class=\"language-text\">git init</code> command to initialize a git repository.</p>\n<p><img src=\"https://user-images.githubusercontent.com/10103699/132892333-a9154705-6ff1-405a-b94f-4e4305a94c06.png\" alt=\"git4\"></p>\n<h4>3. Add existing files to the repository.</h4>\n<p>Use <code class=\"language-text\">git add --all</code> to add all the files in the folder to the Git repository.\nThen use <code class=\"language-text\">git commit -m &quot;Commit message&quot;</code> to record the changes made to the project. The commit message describes the\nchange you made to the project.</p>\n<p><img src=\"https://user-images.githubusercontent.com/10103699/132892344-2f0b788e-7bc8-4680-80b6-28fdb2046d0b.png\" alt=\"git5\"></p>\n<h4>4. Link your project with the repository created in GitHub.</h4>\n<p>Execute <code class=\"language-text\">git remote add &lt;repository-name&gt; &lt;url&gt;</code> to add your project in your machine to the repository. Here,\nrepository-name is the name you want your remote repository to have. This can be the same as your GitHub repository\nname, but does not necessarily have to be so.</p>\n<p><img src=\"https://user-images.githubusercontent.com/10103699/132892354-7de1c94a-be6f-4303-9227-574e3f61eeb4.png\" alt=\"git6\"></p>\n<p>You can get the url of the repository using GitHub.</p>\n<p><img src=\"https://user-images.githubusercontent.com/10103699/132892359-bf1a1396-8913-405d-afff-d1fb6f5ce6cc.png\" alt=\"git7\"></p>\n<h4>5. Push the project to the repository.</h4>\n<p>Use <code class=\"language-text\">git push &lt;repository-name&gt; master</code> to push your project to the remote repository. The repository-name has to be\nthe same as the one specified earlier in step 4. This will prompt you to enter the username and password of the\nGitHub account and record changes in the repository.</p>\n<p><img src=\"https://user-images.githubusercontent.com/10103699/132892364-52a22571-ab94-436d-be4b-6a995665bb7a.png\" alt=\"git8\"></p>\n<h4>6. Checking status</h4>\n<p>Use <code class=\"language-text\">git status</code> command to check the status of the repository at any time to check if there are any changes to be\ncommitted or pushed.</p>\n<p><img src=\"https://user-images.githubusercontent.com/10103699/132892370-095bfea9-22ed-402c-ab04-16409a282cd0.png\" alt=\"git9\"></p>\n<h4>7. Finding the remote repository name</h4>\n<p>Use <code class=\"language-text\">git remote show</code> to get the remote repository name.</p>\n<p><img src=\"https://user-images.githubusercontent.com/10103699/132892379-96665e0c-9e72-40ab-999b-22761a33f3f8.png\" alt=\"git10\"></p>\n<h4>8. Recording changes made later</h4>\n<p>After making any changes to the project, the changes have to be committed and pushed to the repository to record\nthe changes in Git. Follow steps 3 and 5 to push the repository again.</p>\n<h4>9. Updating changes from others in your machine</h4>\n<p>To get the changes made by others to the repository, run the command <code class=\"language-text\">git pull &lt;remote-name&gt; &lt;branch-name&gt;</code>. The\nbranch-name is 'master' by default, as we did not discuss branching in this post. Make sure you have committed and\npushed your changes before pulling the updates.</p>\n<p><img src=\"https://user-images.githubusercontent.com/10103699/132892387-dce874fa-766a-4b25-94dc-1e4f09609ff5.png\" alt=\"git11\"></p>\n<p>It is in this step where conflicts can occur. If you run into any conflicts, those will have to be resolved manually.</p>\n<h3>Cloning an existing repository to your computer</h3>\n<p>Go to the directory in your computer and open a command window using Shift+Right click. Use <code class=\"language-text\">git clone &lt;url to the \nrepository&gt;</code> to get the existing repository to your computer. The repository will be cloned in your computer creating\na new folder.</p>\n<p><img src=\"https://user-images.githubusercontent.com/10103699/132892394-fc0c0799-d21f-49c6-9d73-6cc3368e1919.png\" alt=\"git12\"></p>\n<p>Committing and pushing changes to the repository is the same as in above steps. Make sure that you are inside the\nproject folder when executing the commands.</p>\n<p>Happy coding with Git!</p>","frontmatter":{"date":"December 13, 2015","path":"/using-git-in-cmd","title":"A Simple Guide to using Git in Command Line","tags":["Git","How to"]}}},"pageContext":{}},"staticQueryHashes":["3649515864"]}