{"id":335,"date":"2020-08-24T16:33:01","date_gmt":"2020-08-24T14:33:01","guid":{"rendered":"http:\/\/www.myblog.nguenkam.com\/?p=335"},"modified":"2020-08-24T16:56:34","modified_gmt":"2020-08-24T14:56:34","slug":"create-a-remote-git-branch","status":"publish","type":"post","link":"https:\/\/nguenkam.com\/blog\/index.php\/2020\/08\/24\/create-a-remote-git-branch\/","title":{"rendered":"create a remote Git branch?"},"content":{"rendered":"\n<p>First, you create your branch locally:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git checkout -b &lt;branch-name> # Create a new branch and check it out<\/code><\/pre>\n\n\n\n<p>The remote branch is automatically created when you push it to the remote server. So when you feel ready for it, you can just do:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git push &lt;remote-name> &lt;branch-name> <\/code><\/pre>\n\n\n\n<p>Where&nbsp;<code>&lt;remote-name&gt;<\/code>&nbsp;is typically&nbsp;<code>origin<\/code>, the name which git gives to the remote you cloned from.Your colleagues would then just pull that branch, and it&#8217;s automatically created locally. Or they can reach your branch, by doing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git fetch\ngit checkout origin\/your_branch<\/code><\/pre>\n\n\n\n<p>Note however that formally, the format is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git push origin &lt;local-branch-name>:&lt;remote-branch-name><\/code><\/pre>\n\n\n\n<p>But when you omit one, it assumes both branch names are the same.Having said this, as a word of&nbsp;<strong>caution<\/strong>, do not make the critical mistake of specifying only&nbsp;<code>:&lt;remote-branch-name&gt;<\/code>&nbsp;(with the colon), or the remote branch will be deleted!<\/p>\n\n\n\n<h4 class=\"has-vivid-red-color has-text-color\">Upstream<\/h4>\n\n\n\n<p>So that a subsequent&nbsp;<code>git pull<\/code>&nbsp;will know what to do, you might instead want to use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git push --set-upstream origin &lt;local-branch-name> <\/code><\/pre>\n\n\n\n<p>or ( Short-form)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git push -u origin &lt;local-branch-name> <\/code><\/pre>\n\n\n\n<p>As described below, the&nbsp;<code>--set-upstream<\/code>&nbsp;option sets up an upstream branch. git sets the new branch as a remote track branch (tracking):<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p> Adding a remote tracking branch means that git yet  knows what you want to do when you git fetch, git pull, or git push in the future. This assumes that you want the local branch and the remote branch  to be in sync.<\/p><\/blockquote>\n\n\n\n<p>it means now we can simply  write  command   (example: &#8220;git fetch&#8221; ) without any option. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git push origin &lt;local-branch-name> <\/code><\/pre>\n\n\n\n<p>can now be (short) written as :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git push <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>First, you create your branch locally: The remote branch is automatically created when you push it to the remote server. So when you feel ready for it, you can just do: Where&nbsp;&lt;remote-name&gt;&nbsp;is typically&nbsp;origin, the name which git gives to the remote you cloned from.Your colleagues would then just pull that branch, and it&#8217;s automatically created [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[60],"tags":[62,61,63],"_links":{"self":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/335"}],"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=335"}],"version-history":[{"count":6,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/335\/revisions"}],"predecessor-version":[{"id":342,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/335\/revisions\/342"}],"wp:attachment":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}