Wednesday, November 19, 2014

How to check whether a pull is needed from remote and create new branch?

The easiest way to do this:
Assume your remote origin is called "origin", you can check by "$ git remote show"
$ git fetch origin

See if there are any incoming changes:
$ git log HEAD..origin/master --online
or
$ git rev-list HEAD...origin/master --count

If any commits are listed in the output above, then you have incoming changes, you need to merge ($ git merge origin/master). If no commits are listed by the above command, then your origin/master is clean.

List all the remote branches and make sure your branch doesn't exist:
$ git branch -r
  origin/HEAD -> origin/master
  origin/branch1
  origin/branch2
  origin/branch3
  ...

Create a branch on the local machine and switch in this branch:
$ git checkout -b branch10

Make sure you switched to the new branch:
$ git branch -vv
  master                   6d16c81 [origin/master] Merge pull request #885
* branch10                 6d16c81 Merge pull request #885

Push the branch on github:
$ git push origin branch10

Confirm your new branch exists in the remote:
$ git branch -r | grep branch10
  origin/branch10
 

Make your change....

Push changes from local to remote:
$ git push origin branch10

No comments: