{"id":859,"date":"2015-03-23T16:18:51","date_gmt":"2015-03-23T20:18:51","guid":{"rendered":"http:\/\/shirishranjit.com\/blog1\/?page_id=859"},"modified":"2020-06-11T16:25:25","modified_gmt":"2020-06-11T20:25:25","slug":"git-cheatsheet","status":"publish","type":"page","link":"https:\/\/shirishranjit.com\/blog1\/technical-posts\/git-cheatsheet","title":{"rendered":"Git Cheatsheet"},"content":{"rendered":"<p>Git for Github:<\/p>\n<ul>\n<li><a href=\"https:\/\/help.github.com\/articles\/adding-an-existing-project-to-github-using-the-command-line\/\">https:\/\/help.github.com\/articles\/adding-an-existing-project-to-github-using-the-command-line\/<\/a><\/li>\n<li><a href=\"https:\/\/help.github.com\/articles\/adding-a-remote\/\">https:\/\/help.github.com\/articles\/adding-a-remote\/<\/a><\/li>\n<li><a href=\"https:\/\/www.atlassian.com\/git\/tutorials\/git-hooks\/\">https:\/\/www.atlassian.com\/git\/tutorials\/git-hooks\/<\/a> hooks example for git<\/li>\n<li><a href=\"https:\/\/www.mediawiki.org\/wiki\/Gerrit\">https:\/\/www.mediawiki.org\/wiki\/Gerrit<\/a><\/li>\n<\/ul>\n<p>See the diff between local and remote:<\/p>\n<pre>git diff --stat --color remotes\/main\/master..origin\/master<\/pre>\n<p>Create the branch on your local machine and switch in this branch :<\/p>\n<pre>$ git checkout -b [name_of_your_new_branch]<\/pre>\n<p>Push the branch on github :<\/p>\n<pre>$ git push origin [name_of_your_new_branch]<\/pre>\n<p>When you want to commit something in your branch, be sure to be in your branch.<\/p>\n<p>You can see all branches created by using :<\/p>\n<pre>$ git branch<\/pre>\n<p>Which will show :<\/p>\n<pre>* approval_messages\n  master\n  master_clean<\/pre>\n<p>Add a new remote for your branch :<\/p>\n<pre>$ git remote add origin [name_of_your_remote]<\/pre>\n<p>Push changes from your commit into your branch :<\/p>\n<pre>$ git push origin [name_of_your_remote]<\/pre>\n<p>Update your branch when the original branch from official repository has been updated :<\/p>\n<div class=\"highlight highlight-sh\">\n<pre>$ git fetch [name_of_your_remote]<\/pre>\n<\/div>\n<p>Then you need to apply to merge changes, if your branch is derivated from develop you need to do :<\/p>\n<pre>$ git merge [name_of_your_remote]\/develop<\/pre>\n<p><strong>Working with Branch<\/strong><\/p>\n<p>Switching Branch:<\/p>\n<p>Check out branch<\/p>\n<pre>$ git checkout -b [branch name]<\/pre>\n<p>Switch Tracking<\/p>\n<pre>$ git branch -u origin\/[branch name]<\/pre>\n<p>Switch Branch<\/p>\n<pre>$ git checkout [branch name]<\/pre>\n<p><strong>Deleting Branch<\/strong><\/p>\n<p>Delete a branch on your local filesystem :<\/p>\n<pre>$ git branch -d [name_of_your_new_branch]<\/pre>\n<p>To force the deletion of local branch on your filesystem :<\/p>\n<pre>$ git branch -D [name_of_your_new_branch]<\/pre>\n<p>Delete the branch on github :<\/p>\n<pre>$ git push origin :[name_of_your_new_branch]<\/pre>\n<p>Recover a File that you deleted that you have not committed:<\/p>\n<pre>$ git checkout {file path}<\/pre>\n<h2>How to setup Commit-Id in GIT<\/h2>\n<h2>GIT Errors<\/h2>\n<ul>\n<li>git -&gt; Fatal: bad Object Head<\/li>\n<li><strong>Resolution &#8211; do git pull &#8211; following is an example<\/strong>\n<pre>$ git pull origin master<\/pre>\n<\/li>\n<\/ul>\n<h2>Git Revert Changes<\/h2>\n<ul>\n<li>\n<pre>git reset --hard $commit-hash\ngit push -f $remote $local_branch$:$remote_branch$\ngit push $local_branch$ $remote_branch$ --force\n<\/pre>\n<\/li>\n<\/ul>\n<h2>Git Clone Error in Windows:<\/h2>\n<p>Following error occurs when doing git clone. This error is due to that you did a copy and paste and it has extra characters. If you type in the whole command it will work.<\/p>\n<pre><code>git clone ssh:\/\/git@.......\n\nCloning into 'xxx projectnam'...\nfatal: protocol 'https' is not supported<\/code><\/pre>\n<h2>GIT trace settings<\/h2>\n<pre class=\" language-none\"><code class=\" language-none\">export GIT_TRACE_PACKET=1\nexport GIT_TRACE=1 \nexport GIT_CURL_VERBOSE=1<\/code><\/pre>\n<p><strong>References<\/strong>:<\/p>\n<ol>\n<li><a href=\"https:\/\/git.eclipse.org\/r\/Documentation\/user-changeid.html\">https:\/\/git.eclipse.org\/r\/Documentation\/user-changeid.html<\/a><\/li>\n<li><a href=\"https:\/\/gerrit.googlecode.com\/svn\/documentation\/2.0\/cmd-hook-commit-msg.html\">https:\/\/gerrit.googlecode.com\/svn\/documentation\/2.0\/cmd-hook-commit-msg.html<\/a><\/li>\n<li><a href=\"https:\/\/wiki.opendaylight.org\/view\/GIT_Cheat_Sheet\">https:\/\/wiki.opendaylight.org\/view\/GIT_Cheat_Sheet<\/a><\/li>\n<\/ol>\n<div class=\"twttr_buttons\"><div class=\"twttr_twitter\">\n\t\t\t\t\t<a href=\"http:\/\/twitter.com\/share?text=Git+Cheatsheet\" class=\"twitter-share-button\" data-via=\"\" data-hashtags=\"\"  data-size=\"default\" data-url=\"https:\/\/shirishranjit.com\/blog1\/technical-posts\/git-cheatsheet\"  data-related=\"\" target=\"_blank\">Tweet<\/a>\n\t\t\t\t<\/div><div class=\"twttr_followme\">\n\t\t\t\t\t\t<a href=\"https:\/\/twitter.com\/shiranjit\" class=\"twitter-follow-button\" data-size=\"default\"  data-show-screen-name=\"false\"  target=\"_blank\">Follow me<\/a>\n\t\t\t\t\t<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Git for Github: https:\/\/help.github.com\/articles\/adding-an-existing-project-to-github-using-the-command-line\/ https:\/\/help.github.com\/articles\/adding-a-remote\/ https:\/\/www.atlassian.com\/git\/tutorials\/git-hooks\/ hooks example for git https:\/\/www.mediawiki.org\/wiki\/Gerrit See the diff between local and remote: git diff &#8211;stat &#8211;color remotes\/main\/master..origin\/master Create the branch on your local machine and switch in this branch : $ git checkout -b &hellip; <a href=\"https:\/\/shirishranjit.com\/blog1\/technical-posts\/git-cheatsheet\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":198,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-859","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/859"}],"collection":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/comments?post=859"}],"version-history":[{"count":22,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/859\/revisions"}],"predecessor-version":[{"id":1857,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/859\/revisions\/1857"}],"up":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/198"}],"wp:attachment":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/media?parent=859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}