What is git diff remote ?
Git diff-remote is a bash script which aids in showing the difference between two branches of development via git remote. In essence, it allows the user to simplify git branch operations on two remote branches.
The script takes two arguments, the first being the branch which will be the “remote” (assuming it is not merged), and the second is a text string. This text string is used to provide extra information in case you wish to track commits from some other version control system .
A git diff-remote script for CentOS 7 and Red Hat Enterprise Linux 7: http://lesons.io/gits-dif…
For Red Hat Enterprise Linux 6, see http://lesons.io/gits-d…
for git version 1.7.1+ to 2.3.1+: http://lesons.io/gits-dif…
for git version 1.6+ to 2.2+, if you need a very fast diff: http://lesons.io/gits-dif…
for git version 1.5.1+ to 1.8.2+: http://lesons.io/gits-dif…
for git version 1.4+ to 1.7+, if you need a fast diff for 2 systems: http://lesons.io/gits-dif…
How to use git diff remote ?
Execute git diff-remote command for two remote branches and it will show you a graphical representation of the differences between the two branches. You can also get the differences between all remote branches. git diff-remote.
git diff-remote master production:
The above command will show all the changes between master branch and production branch.
How to merge two branches?
Use the below command to do it. Also you can use this to merge a local branch with another remote branch(These are normal git commands, nothing special). There is a good chance you wouldn’t even require using this command if you are a git pro :P.
How to compare two remote branches?
This command will clearly show the differences between two remote branches, it’ll also tell you where the differences are located and the diffstat will tell you which lines have changes and how they differ.
$ git diff-remote –exclude=’origin’ master production
The above command is used to compare the production branch with a remotely hosted master branch. It’ll exclude (from comparison) mutual ancestry(origin) from both branches (master and production).
Merging two remote branches
This will merge branches of the type that are different from each other, i.e., not master and production. The above command will result in the creation of a new branch (to be named “merge” in this example).
What are the benefits of using git diff remote ?
Git diff-remote makes it easy for the developer to share ideas, code changes and bug fixes by comparing and merging them via git. Also, you can view the changes from a single repository or from all repositories in a project. If you are making a significant change to one of your project’s branch of development, simply use git diff-remote to show the difference and get review, approval or feedback from your team mates.
To add a remote reference to your local repository, type:
git remote add [REMOTE]
where the remote is to be added. Example: git remote add origin my_branch_of_development
The next time you commit changes to your local repository with git commit, changes are automatically pushed to the specified remote remote. The last step is typing : git push origin [REMOTE]
The example below demonstrates how a developer makes commits and pushes them to his/her feature branch.
Examples of how to use git diff remote .
In the first example, you can see two different branches of development. The first one is called “master” (line 2) and the second one is called “feature-x” (line 3). Now, you can see that “master” has the following commits:
– git commit c5d5f57e1ecbb8bd2fc07a59a459da61d0c7f9c4
– git commit d543288bdb7681fd63c2eb796230df169f77ef50
– git commit 6677efea7e619aa56caf4af4373edf68eb4574ce
– git commit bde835.
You can see the commits – each commit has its own commit message. And you can see also that “feature-x” is a new branch of development. It has only one commit:
– git checkout -b feature-x d543288bdb7681fd63c2eb796230df169f77ef50
Now, the following command will show all commits made in each branch: “git rev-list master.” Note that this is a very useful command. You can also see all commits made in “feature-x” by typing the following command: “git rev-list feature-x.”