In this post you will learn how to work in Git branches like: create, delete, merge branch data.
1. List all branches of your repository.
2. Create new branch.
3. Delete the specified branch. This is a “safe” operation in that Git prevents you from deleting the branch if it has unmerged changes.
4. Force delete the specified branch, even if it has unmerged changes
5. Rename the current branch, this command rename the current branch.
6. Switch branch, this command switch the current branch to selected branch.
Use flag –b to crated branch first if not exist then it will switch to created new branch
7. Merge branch to current selected branch.
It will merger master branch code automatically to current branch.
Example : when many developer are working and they are checkin their code into master branch, so you need to merger master code to your qa branch. In this example I download code from master remote branch, merge to qa branch and then push to remote qa branch.
1. List all branches of your repository.
$ git branch
2. Create new branch.
$ git branch {branchName}
Example:
$git branch qa
3. Delete the specified branch. This is a “safe” operation in that Git prevents you from deleting the branch if it has unmerged changes.
$ git branch -d {branchName}
Example:
$git branch -d qa
4. Force delete the specified branch, even if it has unmerged changes
$ git branch -D {branchName}
Example:
$git branch –D qa
5. Rename the current branch, this command rename the current branch.
$ git branch -m {branchName}
Example:
$git branch –m qa1
6. Switch branch, this command switch the current branch to selected branch.
$ git checkout {existing branch}
Example:
$git branch qa1
$ git checkout -b {new branch}
Example:
$git branch qa
7. Merge branch to current selected branch.
$ git merge {branch}
Example:
$git branch master
Example : when many developer are working and they are checkin their code into master branch, so you need to merger master code to your qa branch. In this example I download code from master remote branch, merge to qa branch and then push to remote qa branch.
$git checkout master ( command
switch your master branch)
$git pull ( Download all updated code from master branch to
your local master branch)
$ git checkout qa (switch to qa branch )
$ git merge master (merge master branch code to qa
branch in local)
$ git push (pushed local code into remote
branch )
No comments:
Post a Comment
Leave your comments, queries, suggestion I will try to provide solution