{"id":2927,"date":"2012-01-09T20:03:24","date_gmt":"2012-01-09T15:03:24","guid":{"rendered":"http:\/\/aasims.wordpress.com\/?p=2927"},"modified":"2025-04-29T17:46:22","modified_gmt":"2025-04-29T17:46:22","slug":"daily-git","status":"publish","type":"post","link":"https:\/\/aasimnaseem.com\/blog\/daily-git\/","title":{"rendered":"Daily Git"},"content":{"rendered":"<p>Hi everyone;<\/p>\n<p>So long its been when I last posted anything on my blog; The reason was again the same, some tight schedules and some other home activities; But Notw I&#8217;m back; Say welcome please; (:<\/p>\n<p>Today&#8217;s post is simple; Now a days me and my team is using Git for our code management; So here are some git commands for daily usage; I&#8217;m not going to describing their usage in details; This post is for busy developer who just want to know the exact syntax of a command for a particular requirement;<\/p>\n<p>So here we go &#8230;<\/p>\n<p><!--more--><\/p>\n<p><strong>updated on 10 jan, 2k12:<\/strong><br \/>\n<span style=\"text-decoration: underline;\"><em>git-blame<\/em><\/span>\u00a0 Show what revision and author last modified each line of a file;<br \/>\n<span style=\"text-decoration: underline;\"><em>git branch<\/em><em> \u2013contains<\/em><\/span><em>\u00a0<\/em>Only list branches which contain the specified commit;<\/p>\n<p><strong>updated on 21 Dec, 2k12:<br \/>\n<\/strong>Every command has its own set of options, which are used with hyphen sign; Like commit command has one option -m with is used to provide a commit message; In this post I&#8217;m not covering the options&#8217;s details in depth; This article is only for a quick reference;<\/p>\n<p><strong>Fetching code from a repository;<br \/>\n<\/strong><span style=\"text-decoration: underline;\"><em>git clone git@IP-ADDRESS<em>&#8211;<\/em>OR<em>&#8211;<\/em>URL<em>&#8211;<\/em>OF<em>&#8211;<\/em>SERVER:example.git<\/em><\/span><br \/>\nThis command will download all code from a particular git repository to your system; This is equivalence to SVN\/CVS checkout;<\/p>\n<p><span style=\"text-decoration: underline;\"><em>git pull origin &lt;branch name&gt;<\/em><\/span>\u00a0Will fetch updated code from remote repository to your system; Its just like update in SVN\/CVS;<\/p>\n<p><strong>Play with branches<\/strong><\/p>\n<p><span style=\"text-decoration: underline;\"><em>git branch <\/em><\/span>Will display all branches of your current repository<br \/>\n<span style=\"text-decoration: underline;\"><em>git branch dev <\/em><\/span>Will create a new branch named dev, to current repository; Note that this branch is only to your local repository;<br \/>\n<span style=\"text-decoration: underline;\"><em>git checkout dev <\/em><\/span>You will be switched to dev branch locally;<br \/>\n<em><span style=\"text-decoration: underline;\">git checkout -f B2\u00a0<\/span><\/em>\u00a0Forcefully switch to B2, reverting all your changes of current working branch;<\/p>\n<p><strong>To commit your code<br \/>\n<\/strong><em><span style=\"text-decoration: underline;\">git status<\/span><\/em>\u00a0Will show all your changes for current working branch;<\/p>\n<p><span style=\"text-decoration: underline;\"><em>git add &lt;file\/directory name&gt; <\/em><\/span>Will add a file or directory in commit queue of git; This commit is only to your local repository; You can add one or more files\/directories with this command;<\/p>\n<p>Tip: If there are more then on file in a directory, then just use the directory name in <em><span style=\"text-decoration: underline;\">add<\/span><\/em> command and git add will all modified files to commit queue itself;<\/p>\n<p><span style=\"text-decoration: underline;\"><em>git add\u00a0<strong>&#8211;<\/strong>u<\/em><\/span>\u00a0will removed deleted files from git status message; Sometimes many deleted files are shown in git status log, so this command will remove those deleted files form git&#8217;s logs;<\/p>\n<p><span style=\"text-decoration: underline;\"><em>git commit -m &#8220;message&#8221;<\/em><\/span>\u00a0Will commit the previously added files to current local repository;<\/p>\n<p><span style=\"text-decoration: underline;\"><em>git push origin dev<\/em><\/span><em>\u00a0<\/em>will send your changes from local repository to remove git repository; This action is same as commit in\u00a0svn; Now your code is actually submitting to remote server;<\/p>\n<p><strong>To merger code from B1 branch to B2 branch<\/strong><\/p>\n<p>Assuming that you have pushed all your local changes to remote B1 branch ;<\/p>\n<p><span style=\"text-decoration: underline;\"><em>git checkout B2\u00a0<\/em><\/span>Will switch you from previous branch to B2 branch;<br \/>\n<span style=\"text-decoration: underline;\"><em>git merge B1\u00a0<\/em><\/span>Will merge the code in B2, from B1; (The code of B1 will be merged in B2 and B1 will remain intact) Again note that this change will occur only to your local repository;<br \/>\n<em><span style=\"text-decoration: underline;\">git push origin B2\u00a0<\/span><\/em>\u00a0Will push your code to remove B2 branch, from your local repository;<\/p>\n<p><strong>To Revert your changes in local repository<\/strong><\/p>\n<p><em><span style=\"text-decoration: underline;\">git checkout path\/to\/file\/to\/revert\u00a0<\/span><\/em>This will revert all the changes of a single file; It checksouts the current index for the current directory, throwing away all changes in files from the current directory downwards.<\/p>\n<p><em><span style=\"text-decoration: underline;\">git reset &#8211;hard HEAD<\/span><\/em>\u00a0Will revert all of your changes in current working branch; The command is save as <span style=\"text-decoration: underline;\"><em>svn revert -R .<\/em><\/span><\/p>\n<p>If you know any command of git for daily use, just dont&#8217; hesitate to share with us;<br \/>\nHappy Development; (:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/s06.flagcounter.com\/count\/pCuL\/bg_FFFFFF\/txt_000000\/border_FFFFFF\/columns_6\/maxflags_248\/viewers_0\/labels_1\/pageviews_1\/flags_0\/\" alt=\"free counters\" border=\"0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi everyone; So long its been when I last posted anything on my blog; The reason was again the same, some tight schedules and some other home activities; But Notw I&#8217;m back; Say welcome please; (: Today&#8217;s post is simple; Now a days me and my team is using Git&#8230;<\/p>\n","protected":false},"author":1,"featured_media":4996,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1144],"tags":[282,408,409,410,411,412,413,414,415,416,417,508],"class_list":["post-2927","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code-repositories","tag-commit-code-in-git","tag-git","tag-git-add","tag-git-branch","tag-git-checkout","tag-git-clone","tag-git-commit","tag-git-merge","tag-git-pull","tag-git-push","tag-git-reset","tag-how-to-revert-single-file-git"],"_links":{"self":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/2927","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/comments?post=2927"}],"version-history":[{"count":3,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/2927\/revisions"}],"predecessor-version":[{"id":5221,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/2927\/revisions\/5221"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/media\/4996"}],"wp:attachment":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/media?parent=2927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/categories?post=2927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/tags?post=2927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}