Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BitBucket push to feature branch model

Tags:

git

bitbucket

I created a new branch on bitbucket server (private hosted). Bitbucket have multiple branch types like "hotfixes", "feature", etc. I created one using the "feature" branch model. The branch name in the branch list became "feature/mybranchname". I do the usual git fetch, git checkout -b mybranchname origin/feature/mybranchname and start working.

But the problem is that whatever new changes i made in the branch "mybranchname" cannot be pushed to the remote. Whenever git push executed, only master will get updated, even though the git status says X commits ahead of "origin/feature/mybranchname".

git push -u origin mybranchname will create a new branch on the server without the "feature" name, therefore it's duplicated into a new branch.

git push feature/mybranchname will return the following.

fatal: 'feature/mybranchname' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

```

Found this similar question, but without any solution. Found this documentation from atlassian stating what is branching model and such, but without any mentioning of how to push to them.

Expected result: the local commits from "mybranchname" gets pushed to remote's "feature/mybranchname" without doing a merge from the web UI.

like image 849
thuyein Avatar asked Dec 20 '25 09:12

thuyein


2 Answers

You need to specify the remote repo:

gut push -u origin feature/mybranchname

Then your local feature/mybranchname will be linked to its remote tracking counterpart origin/feature/mybranchname, and a simple git push will then be enough.

The OP adds:

I created a new branch using git checkout -b mybranchname feature/mybranchname but instead it should be just git checkout feature/mybranchname

Yes, because the git checkout man page mentions:

git checkout <branch>

If <branch> is not found but there does exist a tracking branch in exactly one remote (call it ) with a matching name, treat as equivalent to

git checkout -b <branch> --track <remote>/<branch>

Note that in that case, you do not need git push -u origin feature/mybranchname: again, a simple git push is enough, since the local branch is already linked to the remote tracking branch.

like image 130
VonC Avatar answered Dec 21 '25 23:12

VonC


I think you can use git checkout feature/mybranchname

And create new branch with git checkout -b mybranchname

And git push -u origin mybranchname

like image 20
Tan Duong Avatar answered Dec 21 '25 23:12

Tan Duong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!