Friday, March 11, 2016

Git working with Branch

There are numers reasons why somebody wants to create a new branch; for example, someone might need to add a new feature to the master branch without reflecting the changes to the master branch. Another reason could be fixing a bug and then merge the modifications to the master branch. Despite the reasons, here I will list main command lines you need to know to work with git branching as following

1- Show remote git URL:
$ git remote show origin 

2- Show git working branch:
$ git branch 

3- Create a new branch from existing one.
git branch <branchName>

4- Switch between branches.
$ git checkout <branchName>

5- To submit the newly created branch to the remote server, only for the first time. 
$ git push -u origin <branchName>

6- Later to submit any changes will be similar to operating with only one branch. 
$ git add --all 
$ git commit -m ' your message.' 
$ git pull 
$ git push 

7- To clone a specific branch
$ git clone -b <branch> <remote> 

8- To merge changes from one branch, e.g, <Fix> to the master branch. 

$ git checkout master
$ git pull origin master 
$ git merge fix
$ git add --all 
$ git commit -m "message "
$ git push origin master 
Example: 
$ git clone -b fixingBug louai@server/project/repository/projectName


Reference : https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell