{"id":1691,"date":"2022-02-23T13:09:15","date_gmt":"2022-02-23T12:09:15","guid":{"rendered":"https:\/\/nguenkam.com\/blog\/?p=1691"},"modified":"2022-02-23T13:34:09","modified_gmt":"2022-02-23T12:34:09","slug":"git-pull-rebase-vs-merge","status":"publish","type":"post","link":"https:\/\/nguenkam.com\/blog\/index.php\/2022\/02\/23\/git-pull-rebase-vs-merge\/","title":{"rendered":"Git pull &#8211;rebase  vs   &#8211;merge"},"content":{"rendered":"\n<h4><span class=\"has-inline-color has-vivid-cyan-blue-color\">rebasing<\/span><\/h4>\n\n\n\n<p>If you pull remote changes with the flag\u00a0<code><em>--rebase<\/em><\/code>, then your local changes are reapplied on top of the remote changes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git pull --rebase<\/code><\/pre>\n\n\n\n<h4><span class=\"has-inline-color has-vivid-cyan-blue-color\">merging<\/span><\/h4>\n\n\n\n<p>If you pull remote changes with the flag\u00a0<code><em>--merge<\/em><\/code>, which is also the default, then your local changes are merged with the remote changes. This results in a merge commit that points to the latest local commit and the latest remote commit.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git pull --merge<\/code><\/pre>\n\n\n\n<h4><span class=\"has-inline-color has-vivid-red-color\">best practice<\/span><\/h4>\n\n\n\n<p>It is best practice to&nbsp;<strong>always rebase your local commits<\/strong>&nbsp;when you pull before pushing them. As nobody knows your commits yet, nobody will be confused when they are rebased but the additional commit of a merge would be unnecessarily confusing. Published commits are, however, usually merged, for example when branches are merged.<\/p>\n\n\n\n<p>To avoid typing\u00a0<code>--rebase<\/code>\u00a0whenever you pull you can config git to use it as default:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git config --global pull.rebase true<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"600\" height=\"239\" src=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/02\/pull-rebase.png\" alt=\"\" class=\"wp-image-1695\" srcset=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/02\/pull-rebase.png 600w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2022\/02\/pull-rebase-300x120.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>rebasing If you pull remote changes with the flag\u00a0&#8211;rebase, then your local changes are reapplied on top of the remote changes. merging If you pull remote changes with the flag\u00a0&#8211;merge, which is also the default, then your local changes are merged with the remote changes. This results in a merge commit that points to the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1694,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[60],"tags":[459,496,495,493,494,63],"_links":{"self":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1691"}],"collection":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1691"}],"version-history":[{"count":3,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1691\/revisions"}],"predecessor-version":[{"id":1696,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1691\/revisions\/1696"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/1694"}],"wp:attachment":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}