{"id":712,"date":"2021-01-08T15:44:16","date_gmt":"2021-01-08T10:14:16","guid":{"rendered":"https:\/\/openapex.org\/spaces\/software\/?p=712"},"modified":"2025-11-19T16:41:25","modified_gmt":"2025-11-19T11:11:25","slug":"git-get-or-refresh-a-file-or-folder-from-the-remote-branch","status":"publish","type":"post","link":"https:\/\/mutesoft.com\/spaces\/software\/git-get-or-refresh-a-file-or-folder-from-the-remote-branch.html","title":{"rendered":"Git &#8211; Refresh a Local File or Folder from the Remote Branch"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/02\/git-e1672746066670.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Git<\/figcaption><\/figure>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/mutesoft.com\/spaces\/software\/git-get-or-refresh-a-file-or-folder-from-the-remote-branch.html\/#1_Context\" >1. Context<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/mutesoft.com\/spaces\/software\/git-get-or-refresh-a-file-or-folder-from-the-remote-branch.html\/#2_Get_a_file_or_folder_from_the_same_remote_branch\" >2. Get a file or folder from the same (remote) branch<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/mutesoft.com\/spaces\/software\/git-get-or-refresh-a-file-or-folder-from-the-remote-branch.html\/#3_Get_a_file_or_folder_from_a_different_branch\" >3. Get a file or folder from a different branch<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/mutesoft.com\/spaces\/software\/git-get-or-refresh-a-file-or-folder-from-the-remote-branch.html\/#4_Get_a_file_or_folder_from_a_specific_commit\" >4. Get a file or folder from a specific commit<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"1-context\"><span class=\"ez-toc-section\" id=\"1_Context\"><\/span>1. Context<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When you have messed up a file or made temporary changes locally (e.g. for debugging) and you want to get rid of the local changes, there is an easy way out. Depending on your scenario, you perhaps want to do one of the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Get the file or folder from the (remote) branch<\/li>\n\n\n\n<li>Get the file or folder from another branch<\/li>\n\n\n\n<li>Get the file or folder from a specific commit<\/li>\n<\/ul>\n\n\n\n<p>In all the above cases, <code>git checkout<\/code> is the way to go. Let us explore.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-ge-a-file-or-folder-from-the-same-remote-branch\"><span class=\"ez-toc-section\" id=\"2_Get_a_file_or_folder_from_the_same_remote_branch\"><\/span>2. Get a file or folder from the same (remote) branch<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Get file.txt from the remote branch\ngit checkout -- &lt;file-path>\n\n# Get my-folder from the remote branch\ngit checkout -- &lt;folder-path><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-get-a-file-or-folder-from-a-different-branch\"><span class=\"ez-toc-section\" id=\"3_Get_a_file_or_folder_from_a_different_branch\"><\/span>3. Get a file or folder from a different branch<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Get a file from a different branch\ngit checkout &lt;another-feature-branch> -- &lt;file-path>\n\n# Get a folder from a different branch\ngit checkout &lt;another-feature-branch> -- &lt;folder-path>\n\n# When you are working on a feature branch and you want to get the content from master\ngit checkout master -- &lt;file-path><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4-get-a-file-or-folder-from-a-specific-commit\"><span class=\"ez-toc-section\" id=\"4_Get_a_file_or_folder_from_a_specific_commit\"><\/span>4. Get a file or folder from a specific commit<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Get a file from a specified commit (hash)\ngit checkout &lt;commit-hash> -- &lt;file-path>\n\n# Get a folder from a specified commit (hash)\ngit checkout &lt;commit-hash> -- &lt;folder-path><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When you have messed up a file or made temporary changes locally (e.g. for debugging) and you want to get rid of the local changes, there is an easy way out.<\/p>\n","protected":false},"author":2,"featured_media":1053,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"Get or Refresh file or folder from a branch or commit","_seopress_titles_desc":"When you have messed up a file or made temporary changes locally (e.g. for debugging) and you want to get rid of the local changes, there is an easy way out.","_seopress_robots_index":"","_vp_format_video_url":"","_vp_image_focal_point":[],"footnotes":""},"categories":[32],"tags":[38,31,39],"class_list":["post-712","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tools","tag-checkout","tag-git","tag-refresh"],"_links":{"self":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/comments?post=712"}],"version-history":[{"count":14,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/712\/revisions"}],"predecessor-version":[{"id":1629,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/712\/revisions\/1629"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/media\/1053"}],"wp:attachment":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/media?parent=712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/categories?post=712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/tags?post=712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}