{"componentChunkName":"component---src-pages-markdown-remark-fields-slug-js","path":"/engineering/git-pull-force/","result":{"data":{"markdownRemark":{"id":"b6b7417c-1baa-5d47-8d97-0704d063a25d","excerpt":"It is fine when you and the rest of your team are working on different files. But sometimes, multiple people simultaneously work on the same files, and that's…","html":"<p>It is fine when you and the rest of your team are working on different files. But sometimes, multiple people simultaneously work on the same files, and that's where the problems arise.</p>\n<p>Just a Note: <code>git pull = git fetch + git merge</code></p>\n<p>In this scenario, when you have local changes in your system and you pull the latest contribution, you got this error.</p>\n<p><code>error: your local changes to the following files would be overwritten by merge: readme.md</code>\n<code>please commit your changes or stash them before you merge.</code>\n<code>Aborting...</code></p>\n<h2 id=\"now-you-have-2-major-choices\" style=\"position:relative;\"><a href=\"#now-you-have-2-major-choices\" aria-label=\"now you have 2 major choices permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Now you have 2 major choices</h2>\n<h3 id=\"choice-1-you-want-to-keep-local-changes\" style=\"position:relative;\"><a href=\"#choice-1-you-want-to-keep-local-changes\" aria-label=\"choice 1 you want to keep local changes permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Choice 1: you want to keep local changes</h3>\n<p><code>git stash</code>  (stash the local changes clean the workspace)\n<code>git pull</code> (pull the latest changes from remote )\n<code>git stash apply</code> (apply the latest stash)</p>\n<p>-----------(or)---------------</p>\n<p><code>git fetch</code> (fetch the local machine folder)\n<code>git stash</code> (stash the local changes clean the workspace)\n<code>git merge '@{u}'</code> (merge the changes from local folder to workspace folder)\n<code>git stash pop</code> (apply the latest stash )</p>\n<p>By default, the stash changes will become staged. If you want to unstage them, use <code>git restore --staged</code> (git ver > 2.25.0).</p>\n<h3 id=\"choice-2-you-do-not-want-the-local-changes\" style=\"position:relative;\"><a href=\"#choice-2-you-do-not-want-the-local-changes\" aria-label=\"choice 2 you do not want the local changes permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Choice 2: you do not want the local changes</h3>\n<p><code>git reset --hard HEAD</code> (reset to the head means remove all local changes)\n<code>git pull</code> (get the latest changes)</p>\n<p>-----------(or)---------------</p>\n<p><code>git fetch</code> (fetch the local machine folder)\n<code>git reset --hard HEAD</code> (reset to the head means remove all local changes)\n<code>git merge '@{u}'</code>  (merge the changes from the local folder to workspace folder)</p>\n<h2 id=\"git-pull---force\" style=\"position:relative;\"><a href=\"#git-pull---force\" aria-label=\"git pull   force permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>git pull --force</h2>\n<p>Now you must be thinking, what is <code>git pull --force</code> then?</p>\n<p>it feels like it would help to overwrite local changes. instead, it fetches forcefully but does not merge forcefully (<code>git pull --force</code> = <code>git fetch --force</code> + <code>git merge</code>).</p>\n<p>Like git push, git fetch allows us to specify which local and remote branch we want to work on. <code>git fetch origin/ft-1:my-ft</code> means the changes in the <code>ft-1</code> branch from the remote repository will end up visible on the local branch <code>my-ft</code>. When such kind of operation modifies the existing history, it is not allowed by the Git without an explicit --force parameter.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n</style>","headings":[{"value":"Now you have 2 major choices","depth":2},{"value":"Choice 1: you want to keep local changes","depth":3},{"value":"Choice 2: you do not want the local changes","depth":3},{"value":"git pull --force","depth":2}],"fields":{"slug":"/engineering/git-pull-force/"},"frontmatter":{"metatitle":null,"metadescription":null,"description":"How to Overwrite Local Changes With Git Force Pull","title":"How to Perform a Git Force Pull","canonical":null,"date":"December 03, 2020","updated_date":null,"tags":["git"],"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/496c8e02b6dc1da7410a55bf50a19942/701ee/pull.jpg","srcSet":"/static/496c8e02b6dc1da7410a55bf50a19942/3dcee/pull.jpg 200w,\n/static/496c8e02b6dc1da7410a55bf50a19942/ae6ae/pull.jpg 400w,\n/static/496c8e02b6dc1da7410a55bf50a19942/701ee/pull.jpg 800w,\n/static/496c8e02b6dc1da7410a55bf50a19942/8c3c2/pull.jpg 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Abhimanyu Singh Rathore","github":"abhir9","bio":"He is a fun-loving technocrat, artist, photographer, nature lover, leisure traveler, and developer. He actively develops full-stack apps and programs in Go and various JavaScript frameworks and libraries, especially React.","avatar":null}}}},"pageContext":{"id":"b6b7417c-1baa-5d47-8d97-0704d063a25d","fields__slug":"/engineering/git-pull-force/","__params":{"fields__slug":"engineering"}}},"staticQueryHashes":["1171199041","1384082988","1711371485","1753898100","2100481360","229320306","23180105","528864852"]}