Git is a very wonderful and revision management system as we all developer know it. Git has itself an advance level bus architecture. Today Git is very useful for every IT industries they are using it very frequently. But still Git has hold many hidden features, which we have not know yet. So today I am going to share one of them.
It is Upstream and Downstream. Before trying to understand what the upstream tracking branch is, you need to be familiar with remote branches (e.g. origin/master). If you are not, you probably want to read the section about them in the Pro Git book here.
To see all your remote tracking branches, you can use
git branch –remotes
The upstream tracking branch
Even if you have never heard of the concept, you probably already have at least one upstream tracking branch: master -> origin/master. When you clone a repository the current HEAD (usually ‘master’) is checked out for you, but also, it’s setup to track ‘origin/master’, and thus ‘origin/master’ is the “upstream” of ‘master’.
This has some implications on some Git tools, for example, when you run ‘git status‘ you might see a message like this:
# Your branch is behind 'origin/master' by 1 commit.
This is useful in order to keep your local branches synchronized with the remote ones, but it’s only scratching the surface.
A downstream repository (aka a “fork”) maintainer commonly needs to stay current with upstream work. The following steps allow you to achieve this on the command line in a local git repository.
Add the Remote Upstream Repository
This step defines the upstream repository of your fork.
$ git remote add upstream [Upstream git URL]
Fetch the Upstream Branches
$ git fetch upstream
Merge Upstream Changes into your Downstream Repository
From your master branch, use the following merge command to merge the upstream master branch changes into your local source:
$ git merge upstream/master
Create a New Branch for Work
Create a branch off of the master branch that will include the new work. While working in the master branch, execute the following (with any appropriate branch name in quotes):
$ git checkout -b "feature-new-stuff"
Here, we defined the branch feature-new-stuff and will perform work there.
Perform Your Local Work
Follow the standard local repository workflow of file changes with git add . git commit steps for the files.
Push Changes to Your Downstream Remote Repository
When you are ready to push changes to your remote fork of the upstream repository, use the following:
$ git push origin feature-new-stuff
Your local and remote downstream repositories are now current with your local feature-new-stuff changes and this branch is current with the upstream repository changes as of the time of the merge step above.
Hi there! I am Founder at devtantra and programming enthusiast. My skills includes Android, iOS, PHP, React JS and ReactNative and lot more. If you have any idea that you would want me to develop? Let’s talk: firstname.lastname@example.org with subject Devtantra