{"id":41467,"date":"2023-12-01T05:05:29","date_gmt":"2023-12-01T05:05:29","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=41467"},"modified":"2023-12-01T05:05:31","modified_gmt":"2023-12-01T05:05:31","slug":"git-how-to-update-your-outdated-branch","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/git-how-to-update-your-outdated-branch\/","title":{"rendered":"Git: How to update your outdated branch?"},"content":{"rendered":"\n<p><strong>I have 2 branch. develop and feature\/KUB-23446. feature\/KUB-23446 is created from develop but develop have many more changes commited from another branches. How can i update feature\/KUB-23446 with latest changes of develop. Give me multiple approaches.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Approach# 1 &#8211; Merge Way<\/strong><\/h2>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">You can update the feature\/KUB-23446 branch with the latest changes from the develop branch using multiple approaches. Here are three common methods:\r\n \r\nMerge develop into feature\/KUB-23446:\r\n \r\nThis approach involves creating a merge commit to bring the changes from develop into feature\/KUB-23446. It's straightforward and retains a clear history of the branch relationships.\r\n \r\n$ git checkout feature\/KUB-23446\r\n$ git merge develop\r\n \r\nResolve any conflicts if they occur and then commit the merge. Finally, push the updated feature\/KUB-23446 branch to the remote repository if needed.\r\n \r\n$ git push origin feature\/KUB-23446<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\"><strong>Approach# 2 &#8211; Rebase Way<\/strong><\/h2>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Rebase feature\/KUB<span class=\"hljs-number\">-23446<\/span> onto develop:\r\n \r\nThis approach replays the changes <span class=\"hljs-keyword\">from<\/span> feature\/KUB<span class=\"hljs-number\">-23446<\/span> on top <span class=\"hljs-keyword\">of<\/span> the latest develop branch, resulting <span class=\"hljs-keyword\">in<\/span> a linear history without merge commits.\r\n \r\n$ git checkout feature\/KUB<span class=\"hljs-number\">-23446<\/span>\r\n$ git rebase develop\r\n \r\nResolve conflicts <span class=\"hljs-keyword\">if<\/span> they occur during the rebase process. After resolving conflicts, <span class=\"hljs-keyword\">continue<\/span> the rebase <span class=\"hljs-keyword\">with<\/span> git rebase --<span class=\"hljs-keyword\">continue<\/span>. Once the rebase is complete, push the updated feature\/KUB<span class=\"hljs-number\">-23446<\/span> branch.\r\n \r\n$ git push origin feature\/KUB<span class=\"hljs-number\">-23446<\/span>\r\n \r\nBe cautious <span class=\"hljs-keyword\">with<\/span> rebasing, <span class=\"hljs-keyword\">as<\/span> it rewrites commit history. This approach is suitable <span class=\"hljs-keyword\">if<\/span> you want to maintain a cleaner, linear history.\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\"><strong>Approach# 3 &#8211; Cherry-pick<\/strong><\/h2>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\">Cherry-pick individual commits from develop to feature\/KUB-23446:\r\n \r\nIf you want more fine-grained control over which changes from develop are added to feature\/KUB-23446, you can cherry-pick specific commits.\r\n \r\nFirst, checkout the feature\/KUB-23446 branch:\r\n \r\n$ git checkout feature\/KUB-23446\r\n \r\nThen, cherry-pick the commits you want from develop:\r\n \r\n$ git cherry-pick <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">commit-hash1<\/span>&gt;<\/span> <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">commit-hash2<\/span>&gt;<\/span> ...\r\n \r\nReplace <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">commit-hash1<\/span>&gt;<\/span>, <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">commit-hash2<\/span>&gt;<\/span>, etc., with the actual hashes of the commits you want to cherry-pick from develop. After cherry-picking, resolve any conflicts that may arise and commit the changes.\r\n \r\nFinally, push the updated feature\/KUB-23446 branch to the remote repository:\r\n \r\n$ git push origin feature\/KUB-23446<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>","protected":false},"excerpt":{"rendered":"<p>I have 2 branch. develop and feature\/KUB-23446. feature\/KUB-23446 is created from develop but develop have many more changes commited from another branches. How can i update feature\/KUB-23446 with latest changes&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-41467","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/41467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=41467"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/41467\/revisions"}],"predecessor-version":[{"id":41468,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/41467\/revisions\/41468"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=41467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=41467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=41467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}