{"id":12,"date":"2012-10-17T04:29:30","date_gmt":"2012-10-17T04:29:30","guid":{"rendered":"https:\/\/code4reference.com\/?p=12"},"modified":"2012-10-17T04:29:30","modified_gmt":"2012-10-17T04:29:30","slug":"code4referencecode4reference-useful-git-commands","status":"publish","type":"post","link":"https:\/\/code4reference.com\/?p=12","title":{"rendered":"Code4ReferenceCode4Reference: Useful git commands"},"content":{"rendered":"<p><i><b>Clearcase<\/b><\/i> was my first version control software. I used it for 2 years and eventually I liked it since most of the commands are really simple to understand. In these two years I used to debug the code on debugging branch. Once I was done with the fix, I renamed the branch to follow the standard specified by my company. The command below was really handy to rename the branch.<\/p>\n<pre> [cmd-context] $rename replica:old_branch_name new_brach_name \n<\/pre>\n<p>But when I migrated to <i>Git version control<\/i>, I couldn\u2019t get head around\u00a0<i>git<\/i>. It took a while to discover that even git has command to rename the branch which is as following.<\/p>\n<pre>$ git branch -m old-branch-name new-branch-name <\/pre>\n<p>This kind of practice leaves a lot of branches in your local and remote repo and sometimes you wonder to clean this up.<\/p>\n<pre>$git push origin :debug-branch <\/pre>\n<p>The above command will delete debug-branch on the origin remote and below is the command used to delete the branch present in local repo.<\/p>\n<pre>$ git branch -D debug-branch <\/pre>\n<p>This command can also be used with -d option. The only difference between these two commands is that -D forces the delete process but -d doesn\u2019t.<\/p>\n<p>If you have made some changes in a file and now you don\u2019t want those changes. you can run the following command to do that.<\/p>\n<pre>$ git checkout   <\/pre>\n<p>There are instances when you staged the file but now you want to unstage the file. For this use the below command.<\/p>\n<pre>$ git reset HEAD  ...  <\/pre>\n<p>If you have create and new branch and want to push to the remote repo (<code>origin<\/code>) then use the following command<\/p>\n<pre>$git push origin your-branch-here <\/pre>\n<p>and to verify that your branch has been push to origin or not run the following command.<\/p>\n<pre>$git branch -r <\/pre>\n<p>This command basically lists the remote branches.<br \/>\nIf you like to know about the branch which has the specific commit hash code or tag, then use this command.<\/p>\n<pre>git branch --contains  <\/pre>\n<p>Your valuable comments are always welcomed. It will help to improve my post and understanding.<\/p>\n<p>\u00a0 <i>\u201cBy three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest.\u201d<\/i>\u00a0<br \/>\nBy : Confucius<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Clearcase was my first version control software. I used it for 2 years and eventually I liked it since most of the commands are really simple to understand. In these two years I used to debug the code on debugging branch. Once I was done with the fix, I renamed the branch to follow the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12"}],"version-history":[{"count":0,"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts\/12\/revisions"}],"wp:attachment":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}