{"id":5274,"date":"2018-08-22T14:48:34","date_gmt":"2018-08-22T18:48:34","guid":{"rendered":"http:\/\/www.jitendrazaa.com\/blog\/?p=5274"},"modified":"2020-11-19T17:04:50","modified_gmt":"2020-11-19T22:04:50","slug":"frequently-used-git-commands","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/others\/tips\/frequently-used-git-commands\/","title":{"rendered":"Frequently Used Git Commands"},"content":{"rendered":"<h3>Set Git to store credentials<\/h3>\n<p>Below command can be executed from anywhere in your system.<\/p>\n<pre>git config --global credential.helper wincred<\/pre>\n<h3>Turn off Warning _LF will be replaced by CRLF_<\/h3>\n<pre>git config core.autocrlf true\nor\ngit config --global core.autocrlf true<\/pre>\n<p style=\"text-align: justify;\">In Unix systems the end of a line is represented with a line feed (LF). In windows a line is represented with a carriage return (CR) and a line feed (LF) thus (CRLF). when you get code from git that was uploaded from a unix system they will only have an LF.<!--more--><\/p>\n<h3>Mark local folder as git folder<\/h3>\n<pre>git init<\/pre>\n<h3>Add \/ Link remote repository to local repository<\/h3>\n<pre>git remote add origin https:\/\/github.com\/JitendraZaa\/sfdx-object-export<\/pre>\n<h3>Add new \/ multiple remote repository<\/h3>\n<pre>git remote set-url origin  https:\/\/github.com\/JitendraZaa\/sfdx-object-export<\/pre>\n<h3>\u00a0Clone complete repository<\/h3>\n<pre>Git clone\nExample : Git clone https:\/\/github.jitendraZaa.com\/CPQ\/cpq-salesforce.git<\/pre>\n<h3>Clone git repository with branch<\/h3>\n<pre>Git clone -b\nExample : Git clone -b Dev1 https:\/\/github.jitendraZaa.com\/CPQ\/Salesforce-Backup.git<\/pre>\n<h3>Git fast forward push<\/h3>\n<pre>git push --force<\/pre>\n<h3>Ignore a file temporarily or Remove a file from staged area or commit everything except one file<\/h3>\n<p>Run below command before commit, to ignore file<\/p>\n<pre>git reset -- \"FileName\"<\/pre>\n<p>Run below command before commit, to ignore file in folder<\/p>\n<pre>git reset -- \"Folder\/FileName\"<\/pre>\n<p>Run below command before commit, to ignore every file in folder<\/p>\n<pre>git reset -- \"Folder\/*\"<\/pre>\n<h3>Ignore every change in local git repository<\/h3>\n<p>Run below all 3 commands in sequence<\/p>\n<pre>git reset --hard\ngit reset --hard Example : git reset --hard origin\ngit pull<\/pre>\n<h3>Rollback last Git command<\/h3>\n<pre>git lastcommand --revert<\/pre>\n<p>Example if we want to revert last pull command then run below command<\/p>\n<pre>git pull --revert<\/pre>\n<h3>Change or Switch Branch<\/h3>\n<pre>Git checkout<\/pre>\n<h3>Rename Branch<\/h3>\n<pre>git branch -m new-name<\/pre>\n<p>If you are on different branch<\/p>\n<pre>git branch -m old-name new-name<\/pre>\n<p><em><strong>Once Branch renamed, push branch, it will create new and then run delete command for branch<\/strong><\/em><\/p>\n<h3>Delete remote branch<\/h3>\n<pre>git push origin --delete<\/pre>\n<h3>Current code base points to which branch<\/h3>\n<pre>git branch<\/pre>\n<p>starred branch would be current branch<\/p>\n<h3>Create a branch and switch to new branch<\/h3>\n<pre>git checkout -b CPQAdmin<\/pre>\n<p>CPQAdmin is new branch name<\/p>\n<h3>Push branch to remote<\/h3>\n<pre>git push origin CPQAdmin<\/pre>\n<p>CPQAdmin is branch name to be pushed<\/p>\n<h3>Status of modified or added files<\/h3>\n<pre>git status<\/pre>\n<h3>Add all local changed files for commit<\/h3>\n<pre>git add .<\/pre>\n<h3>Delete local deleted file from remote also<\/h3>\n<pre>git add -u .<\/pre>\n<h3>Commit with message<\/h3>\n<pre>git commit -m \"My custom message\"<\/pre>\n<h3>Create gitignore file<\/h3>\n<pre>touch .gitignore<\/pre>\n<p>above command will create gitignore file<\/p>\n<h3>Create tag<\/h3>\n<pre>git tag -a v0.1 -m \"Information about Tag\"<\/pre>\n<h3>Push local tag to remote<\/h3>\n<pre>git push --tags<\/pre>\n<h3>clear git cache<\/h3>\n<p>Sometimes\u00a0 <em><span style=\"text-decoration: underline;\"><strong>gitignore<\/strong><\/span><\/em>\u00a0 file does not work. So, we need to clear the cache using below command<\/p>\n<pre>git rm -r --cached .<\/pre>\n<h3>Get List of files changed in last 24 hours<\/h3>\n<p>Below commands should be executed in\u00a0 <strong>local git folder\u00a0<\/strong><\/p>\n<pre>git pull origin git log --pretty=format: --name-only --since=\"24 hours\" | sort | uniq &gt; OutputFileName.txt<\/pre>\n<p style=\"text-align: justify;\">After running above command, new file with name <em>OutputFileName.txt\u00a0<\/em>\u00a0would be created which will have list of all components changed in last 24 (n) hours.<\/p>\n\n\n<h3 class=\"wp-block-heading\">Save Password in Git Store<\/h3>\n\n\n\n<p>If you are not using SSH keys then you might end up providing password every time. We can run below command to let Git store your password so you don&#8217;t have to remember it<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code brush: powershell; notranslate\"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\ngit config credential.helper store\n<\/pre><\/div>\n\n\n<p>After above command, execute pull request<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code brush: powershell; notranslate\"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\ngit pull\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">List of file changed containing word in commit comments<\/h3>\n\n\n\n<p>Below command will return unique file names by searching words in all commits messages in branch<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit log remoteName\/branchName --grep &quot;word1InCommit\\|word2\\|word3&quot; --pretty=format: --name-only | grep -v -e &quot;^$&quot; | sort | uniq\n<\/pre><\/div>\n\n\n<p>Example<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit log origin\/UAT --grep &quot;profiles changed\\|FLS modified\\|Apex Class for callout&quot; --pretty=format: --name-only | grep -v -e &quot;^$&quot; | sort | uniq\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Remove Remote URL from Git<\/h3>\n\n\n\n<p>Use below command to remove remote URL from git repository. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit remote rm &amp;lt;remote name&gt;\nExample : git remote rm origin\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Keep file locally but delete from remote<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ngit rm --cached somefile.ext\nor\ngit rm --cached somefolder\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Most frequently used Git commands by developers<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[17],"tags":[108],"class_list":["post-5274","post","type-post","status-publish","format-standard","hentry","category-tips","tag-git"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":3086,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-git-eclipse-egit-better-and-distributed-source-control\/","url_meta":{"origin":5274,"position":0},"title":"Salesforce + Git + Eclipse + EGIT = Better and Distributed Source Control","author":"Jitendra","date":"September 16, 2012","format":false,"excerpt":"During my J2EE and .Net days, I was much dependent on the subversion repository. I had never thought my code without SVN. When I moved to Salesforce few years back, the first thing I missed is code repository to have better source code control. As svn creates either \".svn\"\u009d or\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Architecture of GIT","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/09\/Architecture-of-GIT.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":5463,"url":"https:\/\/www.jitendrazaa.com\/blog\/others\/tips\/how-to-setup-git-server-using-bitvise-ssh\/","url_meta":{"origin":5274,"position":1},"title":"How to setup Git Server using Bitvise SSH","author":"Jitendra","date":"April 20, 2016","format":false,"excerpt":"Step by step guide to setup Git Server using Bitvise SSH Server","rel":"","context":"In &quot;Tech Tips&quot;","block_context":{"text":"Tech Tips","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/others\/tips\/"},"img":{"alt_text":"Biwise SSH Server Activity Log","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/04\/Biwise-SSH-Server-Activity-Log.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/04\/Biwise-SSH-Server-Activity-Log.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/04\/Biwise-SSH-Server-Activity-Log.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/04\/Biwise-SSH-Server-Activity-Log.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":3902,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/automated-daily-backup-using-ant-migration-tool-and-git\/","url_meta":{"origin":5274,"position":2},"title":"Automated Daily Backup of Salesforce Using ANT Migration Tool and GIT","author":"Jitendra","date":"July 5, 2014","format":false,"excerpt":"In few\u00a0previous articles, I have talked about how to use \"ANT Migration tool in Salesforce\" and \"How to Use EGit plugin in Eclipse to work with Git\". So to make this article short, I assume that you are already familiar with ANT Migration tool provided by Salesforce and Git. During\u2026","rel":"","context":"In &quot;Configuration&quot;","block_context":{"text":"Configuration","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/configuration\/"},"img":{"alt_text":"Salesforce Automated Script for Data Backup Using CommandLine","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/07\/Salesforce-Automated-Script-for-Data-Backup-Using-CommandLine.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/07\/Salesforce-Automated-Script-for-Data-Backup-Using-CommandLine.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/07\/Salesforce-Automated-Script-for-Data-Backup-Using-CommandLine.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":4756,"url":"https:\/\/www.jitendrazaa.com\/blog\/others\/tips\/fix-git-errors-permission-denied-and-cannot-spawn\/","url_meta":{"origin":5274,"position":3},"title":"Fix Git errors : Permission denied , Cannot spawn , No supported authentication methods available","author":"Jitendra","date":"August 6, 2015","format":false,"excerpt":"Recently, I came across few errors of Git and found very time consuming to fix those. Let's discuss what are those errors and how we can fix it. Error : Permission denied (publickey). fatal : could not read from remote repository This error came while trying to push changes to\u2026","rel":"","context":"In &quot;Tech Tips&quot;","block_context":{"text":"Tech Tips","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/others\/tips\/"},"img":{"alt_text":"Pageant Load existing SSH keys","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/08\/Pageant-Load-existing-SSH-keys.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/08\/Pageant-Load-existing-SSH-keys.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/08\/Pageant-Load-existing-SSH-keys.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":4276,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/continuous-integration-in-salesforce-using-jenkins-and-git-video-tutorial\/","url_meta":{"origin":5274,"position":4},"title":"Continuous integration in Salesforce Using Jenkins and Git | Video Tutorial","author":"Jitendra","date":"March 23, 2015","format":false,"excerpt":"As your Salesforce Organization undergoes heavy customization and frequent builds, moving changes from one Sandbox to other sandboxes starts taking longer time and effort. Also, in normal Salesforce project, there are chances that you will have minimum three sandboxes likely Developer Sandbox, QA Sandbox and UAT Sandbox. After some time\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Salesforce - Jenkins Git Polling Log","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/03\/Salesforce-Jenkins-Git-Polling-Log.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/03\/Salesforce-Jenkins-Git-Polling-Log.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/03\/Salesforce-Jenkins-Git-Polling-Log.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/03\/Salesforce-Jenkins-Git-Polling-Log.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":3930,"url":"https:\/\/www.jitendrazaa.com\/blog\/others\/tips\/resolve-error-eclipse-ssh-key-is-not-matching-the-ssh-keys-that-is-associated-with-your-heroku-account\/","url_meta":{"origin":5274,"position":5},"title":"Resolve Error : Eclipse SSH key is not matching the SSH key(s) that is associated with your Heroku account","author":"Jitendra","date":"July 27, 2014","format":false,"excerpt":"We have seen that how to create First Heroku application using Eclipse.\u00a0However it is possible that after following all steps properly in above article you may receive error saying the Eclipse SSH key is not matching the SSH key(s) that is associated with your Heroku account. To fix this error,\u2026","rel":"","context":"In &quot;Tech Tips&quot;","block_context":{"text":"Tech Tips","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/others\/tips\/"},"img":{"alt_text":"Clone Git from Heroku","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/07\/Clone-Git-from-Heroku.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/07\/Clone-Git-from-Heroku.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/07\/Clone-Git-from-Heroku.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=5274"}],"version-history":[{"count":14,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5274\/revisions"}],"predecessor-version":[{"id":7178,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5274\/revisions\/7178"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=5274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=5274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=5274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}