{"id":63,"date":"2013-07-15T18:41:07","date_gmt":"2013-07-15T18:41:07","guid":{"rendered":"http:\/\/www.theacidfrog.com\/blog\/?p=63"},"modified":"2013-07-15T18:41:07","modified_gmt":"2013-07-15T18:41:07","slug":"basic-git-commands","status":"publish","type":"post","link":"https:\/\/www.theacidfrog.com\/blog\/basic-git-commands\/","title":{"rendered":"Basic Git Commands"},"content":{"rendered":"<p>Here is a list of some basic Git commands to get you going with Git Repositories.<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<th>Task<\/th>\n<th>Description<\/th>\n<th>Command<\/th>\n<\/tr>\n<tr>\n<td><strong>Create a new local repository<\/strong><\/td>\n<td><\/td>\n<td>\n<pre>git init<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td rowspan=\"2\"><strong>Check out a repository<\/strong><\/td>\n<td>Create a working copy of a local repository:<\/td>\n<td>\n<pre>git clone \/path\/to\/repository<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>For a remote server, use:<\/td>\n<td>\n<pre>git clone username@host:\/path\/to\/repository<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td><strong>Add files<\/strong><\/td>\n<td>Add one or more files to staging (index):<\/td>\n<td>\n<pre>git add &lt;filename&gt;\r\n\r\ngit add *<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td rowspan=\"2\"><strong>Commit<\/strong><\/td>\n<td colspan=\"1\">Commit changes to head (but not yet to the remote repository):<\/td>\n<td colspan=\"1\">\n<pre>git commit -m \"Commit message\"<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\">Commit any files you&#8217;ve added with\u00a0<code>git add<\/code>, and also commit any files you&#8217;ve changed since then:<\/td>\n<td colspan=\"1\">\n<pre>git commit -a<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\"><strong>Push<\/strong><\/td>\n<td colspan=\"1\">Send changes to the master branch of your remote repository:<\/td>\n<td colspan=\"1\">\n<pre>git push origin master<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\"><strong>Status<\/strong><\/td>\n<td colspan=\"1\">List the files you&#8217;ve changed and those you still need to add or commit:<\/td>\n<td colspan=\"1\">\n<pre>git status<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td rowspan=\"2\"><strong>Connect to a remote repository<\/strong><\/td>\n<td colspan=\"1\">If you haven&#8217;t connected your local repository to a remote server, add the server to be able to push to it:<\/td>\n<td colspan=\"1\">\n<pre>git remote add origin &lt;server&gt;<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\">List all currently configured remote repositories:<\/td>\n<td colspan=\"1\"><code>git remote -v<\/code><\/td>\n<\/tr>\n<tr>\n<td rowspan=\"7\"><strong>Branches<\/strong><\/td>\n<td colspan=\"1\">Create a new branch and switch to it:<\/td>\n<td colspan=\"1\">\n<pre>git checkout -b &lt;branchname&gt;<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\">Switch from one branch to another:<\/td>\n<td colspan=\"1\">\n<pre>git checkout &lt;branchname&gt;<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\">List all the branches in your repo, and also tell you what branch you&#8217;re currently in:<\/td>\n<td colspan=\"1\">\n<pre>git branch<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\">Delete the feature branch:<\/td>\n<td colspan=\"1\">\n<pre>git branch -d &lt;branchname&gt;<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\">Push the branch to your remote repository, so others can use it:<\/td>\n<td colspan=\"1\">\n<pre>git push origin &lt;branchname&gt;<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\">Push all branches to your remote repository:<\/td>\n<td colspan=\"1\">\n<pre>git push --all origin<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\">Delete a branch on your remote repository:<\/td>\n<td colspan=\"1\">\n<pre>git push origin :&lt;branchname&gt;<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td rowspan=\"4\"><strong>Update from the remote repository<\/strong><\/p>\n<p>&nbsp;<\/td>\n<td colspan=\"1\">Fetch and merge changes on the remote server to your working directory:<\/td>\n<td colspan=\"1\">\n<pre>git pull<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\">To merge a different branch into your active branch:<\/td>\n<td colspan=\"1\">\n<pre>git merge &lt;branchname&gt;<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\">View all the merge conflicts:<\/p>\n<p>View the conflicts against the base file:<\/p>\n<p>Preview changes, before merging:<\/td>\n<td colspan=\"1\"><code>git diff<\/code><\/p>\n<p><code>git diff --base &lt;filename&gt;<\/code><\/p>\n<pre>git diff &lt;sourcebranch&gt; &lt;targetbranch&gt;<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\">After you have manually resolved any conflicts, you mark the changed file:<\/td>\n<td colspan=\"1\">\n<pre>git add &lt;filename&gt;<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td rowspan=\"3\"><strong>Tags<\/strong><\/td>\n<td colspan=\"1\">You can use tagging to mark a significant changeset, such as a release:<\/td>\n<td colspan=\"1\">\n<pre>git tag 1.0.0 &lt;commitID&gt;<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\">CommitId is the leading characters of the changeset ID, up to 10, but must be unique. Get the ID using:<\/td>\n<td colspan=\"1\">\n<pre>git log<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\">Push all tags to remote repository:<\/td>\n<td colspan=\"1\">\n<pre>git push --tags origin<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td rowspan=\"2\"><strong>Undo local changes<\/strong><\/td>\n<td colspan=\"1\">If you mess up, you can replace the changes in your working tree with the last content in head:<\/p>\n<p>Changes already added to the index, as well as new files, will be kept.<\/td>\n<td colspan=\"1\">\n<pre>git checkout -- &lt;filename&gt;<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\">Instead, to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it, do this:<\/td>\n<td colspan=\"1\">\n<pre>git fetch origin\r\n\r\ngit reset --hard origin\/master<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td><strong>Search<\/strong><\/td>\n<td colspan=\"1\">Search the working directory for\u00a0<code>foo()<\/code>:<\/td>\n<td colspan=\"1\"><code>git grep \"foo()\"<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Here is a list of some basic Git commands to get you going with Git Repositories. Task Description Command Create a new local repository git init Check out a repository Create a working copy of a local repository: git clone \/path\/to\/repository For a remote server, use: git clone username@host:\/path\/to\/repository Add files Add one or more&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.theacidfrog.com\/blog\/wp-json\/wp\/v2\/posts\/63"}],"collection":[{"href":"https:\/\/www.theacidfrog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.theacidfrog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.theacidfrog.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.theacidfrog.com\/blog\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":3,"href":"https:\/\/www.theacidfrog.com\/blog\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"predecessor-version":[{"id":66,"href":"https:\/\/www.theacidfrog.com\/blog\/wp-json\/wp\/v2\/posts\/63\/revisions\/66"}],"wp:attachment":[{"href":"https:\/\/www.theacidfrog.com\/blog\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.theacidfrog.com\/blog\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.theacidfrog.com\/blog\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}