Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge branch to master on bitbucket

I have following questions.

  1. I want to create a branch from my master repo. I can use either bitbucket dashboard or Terminal to create a branch. If I used Terminal, the created branch does not show in Overview.but if I used Create a branch from dashboard and create, it shows the branch but din't contains anything and asked me to do checkout with git fetch && git checkout branchname command.
    Which one is the correct way to create a branch?

  2. Then my next question is , Think my master has Changed and my Branch is also chanaged. so how can I merge my branch changes to master. what are the steps to do that. (Best way is to use commands or the bitbucket dashboard merge)

  3. Finally , if we typed git branch, it shows master and other branches. so how can I change the branch from terminal.

like image 464
bill Avatar asked Dec 25 '16 09:12

bill


2 Answers

1) When you create a branch on Bitbucket, that branch does not exist locally. This is probably why the dashboard is recommending that you do git fetch. Git fetch will bring the newly created branch into your local Git. After this, you can do a checkout via git checkout newBranch. Had you created the branch locally, the steps would have happened in reverse. Specifically, the new branch would exist in your local Git, but would not exist on the Bitbucket remote until you did a git push.

In my experience, creating a branch locally via git checkout -b is the typical way to create a branch, as usually this is being done by a developer in his local environment.

2) To merge your branch's changes to master you can try the following:

git checkout master
git merge yourBranch

Keep in mind that it you follow Bitbucket's workflow, the merge might actually be happening as part of a pull request.

3) To switch branches locally, just use git checkout <branch_name>. For example, to switch to yourBranch from master you would type:

git checkout yourBranch
like image 165
Tim Biegeleisen Avatar answered Oct 21 '22 16:10

Tim Biegeleisen


It can be done by using:

  1. checkout to master branch and
  2. git merge your branch.

You will find the complete guide here.

like image 39
techhunter Avatar answered Oct 21 '22 16:10

techhunter