How to create a brand new git tracking branch (from scratch)?
There’s tons of advice on the web on how to setup a new local branch that tracks and existing remote branch. But what I was looking to do is create a brand new branch (i.e. not yet present neither on hte server nor on your workstation) and have it be a tracking branch.
After lots of goolging, reading, and trial and error in new dummy git repositories I figured out 2 ways of doing it. Here they are, the first one being (IMHO) a more elegant solution:
Solution #1
Create a brand new git branch on the server, then start tracking it:
Let’s assume you want to create a remote branch called f1_bugfixes off of an existing remote branch f1. You can then fetch it (since it will be present on the server) and track it with a local tracking branch. Here’s how to do this:
git push origin f1:f1_bugfixes
After executing the above git command the f1_bugfixes branch (or remotes/origin/f1_bugfixes, to be exat) will be present on the remote server, branched off of the f1 (remote) branch.
To track it:
git branch --track f1_bugfixes origin/f1_bugfixes
Solution #2
Create a local branch, do your work, push, then “–set-upstream” to start tracking it:
git checkout f1 # point your repository to where you want to branch off of
git checkout -b f1_bugfixes # create the new local branch
(do your work, add, commit)
git push origin f1_bugfixes # push your branch and the changes on it to the server
git branch --set-upstream f1_bugfixes origin/f1_bugfixes
As you can see approach #2 is lengthier and hence more error-prone.
Another shortcoming of it is that you can not create the branch without pushing some “real” changes to the server. This means that this approach will not work for a project manager who wants to setup a branch point for his/her colleagues. Whereas with the first one you simply stop after step 1, that is after git push origin f1:f1_bugfixes
and, voila – your branch, brand new and EMPTY(!) is created on the server!!
NOTE: As explained in the very beginning – the idea here is to create a brand new branch on the server (and then start tracking it). For all the other folks who want to use your branch the command of course will be (once you create the branch using either approach 1 or 2):
git branch --track f1_bugfixes origin/f1_bugfixes
-
Categories
- Android Development
- Bash
- C programming
- dpkg/apt-get
- drupal
- Emacs
- Git
- Java
- Linux administration
- Linux device drivers
- Linux Gaming
- Linux kernel
- Linux Networking
- Linux on Windows
- Linux printing
- Linux sound and ALSA
- Package Managers
- Programming
- RPM
- Shell and environment
- Tips and tricks
- Uncategorized
- VirtualBox
- Virtualization
- web development
- wine
- WMaker
- Wordpress Tips
- X Window System
- XFCE
-
Articles
- August 2020
- August 2019
- May 2019
- July 2017
- February 2017
- January 2017
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- April 2016
- March 2016
- December 2015
- November 2015
- September 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- October 2014
- February 2014
- January 2014
- November 2013
- October 2013
- June 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- October 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- September 2011
- August 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
-
Meta
Cloud
audio bash boot compile C programming cups drupal emacs etc Fedora git grep how to httpd init kernel libc linux linux partition localtime login make mount mp3 mysql networking oracle package managers password phpMyAdmin programming rpm shell sql vbox version control system virtual box vm web server wordpress www xargs xfce xwin yum