How to merge branch to master on bitbucket
Asked Answered
C

4

13

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.

Cassation answered 25/12, 2016 at 9:49 Comment(0)
C
12

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
Christoper answered 25/12, 2016 at 9:58 Comment(3)
okay, if use terminal to create branch, how we can change Read, write permission. because I created a branch using terminal. when I try to push like git push remote master, it always says Please make sure you have the correct access rights and the repository exists.. why is this.Cassation
This sounds like maybe you are not pointing to the right repository.Christoper
pretty sure I'm in the correct repository. what is the point of Please make sure you have the correct access rights how this part can be happen.Cassation
R
2

It can be done by using:

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

You will find the complete guide here.

Rochelle answered 25/12, 2016 at 10:26 Comment(0)
R
0
  1. Create a new branch from master: git checkout -b newbranch. You may need to push to make the branch available on the remote (git bucket)- git push remote master. I would do this when working on a project. Terminal would be preferable, otherwise you would 'pigeon hole' yourself into working with a specific UI, rather than a consistent CLI.

  2. Make sure your master is upto date, by commiting and pushing any changes and then merge the other branch to master. Again, I would use Terminal.

  3. git checkout otherbranch would change from any branch to otherbranch. Note that the -b flag is not passed in. This will just change the active branch.

Radionuclide answered 25/12, 2016 at 10:6 Comment(1)
okay, if use terminal to create branch, how we can change Read, write permission. because I created a branch using terminal. when I try to push like git push remote master, it always says Please make sure you have the correct access rights and the repository exists.. why is this.Cassation
G
0

You should create a remote branch with the same name as you used on your local repository. with this branch available on the remote repository

You can now do git push

Gabon answered 27/6, 2022 at 9:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.