Pull request creation was canceled when having two branches? - bitbucket

I have two branches in BitBucket server.
1. master
2. feature
Process is:
we have to take the latest code from Master. Once our changes or script creation is done. we will push it to feature for review. If review is approved, it will be merged with master for automation purpose.
First Time,
>> git clone "hosturl"
Make some changes
>> git checkout feature
>> git status
>> git add *
>> git commit -m "test"
>> git push
It is getting pushed in to Feature branch.
From Bitbucket UI, I am trying to CreatePullRequests
It shows select source and destination.
I am selecting source as Feature and Destination as Master and entering reviewer mail id. It is working fine.
The same case for next time onwards I am getting issues
>> git checkout master
>> git pull
Make some changes
>> git checkout feature
>> git status
>> git add *
>> git commit -m "test"
>> git push
It is getting pushed in to Feature branch.
From Bitbucket UI, I am trying to CreatePullRequests
It shows select source and destination.
I am selecting source as Feature and Destination as Master and entering reviewer mail id. It is showing
`Pull request creation was canceled`.
•Please rebase your branch on to the target branch before creating a pull request: git checkout feature; git rebase master; git push -f
When pulling from master and push to feature we are getting the above error. But when clone from master and push to feature working fine as said (first time).
How to resolve this?

I see that your feature branch and master are not in sync. You need to merge the master changes into feature branch.
Try these steps:
git checkout master
git pull
<Make changes>>
git add *
git checkout feature
git commit -m "test"
git merge --no-ff origin master
git push

Related

Reset master to an empty state

I created a new Rails app and pushed the code to Github directly from master (first commit in the repository). However I made a mistake, I didn't want to commit this new Rails app directly from master, but instead create a new branch from master and push the new Rails app from this new branch.
Therefore, I'd like to:
Delete the commit from master in Github(remote), so master is EMPTY
create a new branch from master and add the previous commit that was in master into this new branch.
push it to Github.
Delete the commit from the master in Github(remote), so master is EMPTY
You can create an orphan branch - orphan branch is branch without any history
# Create "clean" branch
git checkout --orphan <name>
# remove all existing content if you wish
git clean -Xdf && git clean -xdf
create a new branch from master and add the previous commit that was in master into this new branch.
few options:
# Option 1 - Start your branch from the last desired commit
git checkout -b <name> <SHA-1>
# Option 2 - Set your branch to the desired commit
git reset <SHA-1> --hard
# Add the required commit on top of your branch
git cherry-pick <SHA-1>
push it to Github.
# force the update of the new branch
git push <origin> master -f
Please create a new branch from the master with the following command,
git checkout -b branch_name
After that checkout into your new branch and push it to Github.
Now go to the master branch and remove the last commit and push it to Github
You can also try the following steps with your repository:
git checkout master: make sure you are in master.
git checkout -b my-fancy-new-branch: create your new feature branch.
git checkout master: switch back to master
git reset --hard rootcommit: reset master to the state before your own commits.
optional and if you have a remote you pull from: git pull --ff (if this fails because the pull is not fast-forward, you have to reconsider rootcommit. It contains some of your work)
I tried to do this on my test repository, it appears to work.
I have taken a reference from this answer, that can help in finding other approaches too.

How push approved commits from one branch to another branch in bitbucket

I have two branches in bitbucket and I want to push only some commits (which are approved by me) from one branch to another branch which is a master branch.
Can someone explain to me how I can do it in the bitbucket environment?
Thanks in advance.
you can use git cherry-pick
steps
1. git log
this will list all commits take the commit id which you wanted to move.
2. git cherry-pick <commit-id>
apply this after switching to master branch
3.then push new master to remote
git push <REMOTENAME> <BRANCHNAME>
eg. git push origin master
or
git push <REMOTENAME> <LOCALBRANCHNAME>:<REMOTEBRANCHNAME>
eg:
if my remote name is heroku and i want to push local heroku branch to heroku(remote) master barnch(heroku/master)
git push heroku heroku:maste
links
What does cherry-picking a commit with git mean?

Git: Merge test repository into master repository

I am new to Git/Heroku/RoR, know basics of these technologies.
I have a git repository repoA which has two branches, master and feature.
I continued working on repoA/feature and upon completion, because the changes were huge so decided to launch a separate app on Heroku to test them first.
So deployed repoA/feature to repoTest/feature on Heroku. Then made some fixes to the feature and finalized the code in repoTest/feature.
Another developer made some commits in repoA/master during this time.
Now I want to make my repoTest/feature LIVE and MERGE it to repoA/master.
Please help me how can I do that ?
NOTE: I have tried doing git rebase master but that did nothing even after a long manual conflict resolve exercise.
As below steps are my normally operations:
1. git checkout repoA/feature
2. git fetch repoTest/feature; git merge repoTest/feature repoA/feature; git stash
3. git checkout repoA/master; git pull origin
4. git checkout repoA/feature; git rebase repoA/master (maybe here you should resolve your conflicts); git stash pop
5. git status; git commit -am ""; git push origin

How can i sync my repository with github?

simple example,
1)made a new project
rails new test_app
2) git commands
git init
git add .
git commit -m "init"
git push origin master
ok finished!
now after this, if i look at github.com webpage gui.
it doesn't show my repository.
How can i set this to my github webpage?
First of all you need to create an repository on github. After that you need to create an ssh key with github for your pc. Befor you can push to the master branch you need to add the remote repository:
git remote add origin git#github.com:yourrepo.git
Than push "origin" to the master branch.

git: how to get changes nicely back into master when working with submodules

i use the git workflow as described in this blogpost.
In short: everybody develops inside his/her own branch, before merging back to master, you rebase your branch to master again to get clean history.
This works.
Now we have a submodule, and because this is an in-house plugin (Rails), we need to change this often. So most of the times i have changes both in the general branch and in the submodule branch.
What is the best way to work with submodules in the workflow as above.
I first try to push my changes to the submodule (git checkout master, git pull, git checkout branch, git rebase master, git checkout master, git merge branch).
Then, when i try to do the same for my root, i always get an error on my plugin (submodule). I have to resolve the error, before doing git rebase --continue. So if try to git mergetool i converts my folder to a file.
After the rebase has ended, i just restore the <folder_name>.orig to overwrite the file <folder_name> and all is well.
But somehow it feels there should be a better way.
In short: when working via checkout-b/rebase/merge - workflow, how do you handle the changed submodules simultaneously?
Whatever workflow you are following with submodules, there is one rule you shouldn't forget:
(From the Git tutorial)
If you want to make a change within a submodule, you should first check out a branch, make your changes, publish the change within the submodule, and then update the superproject to reference the new commit.
$ git checkout master
$ echo "adding a line again" >> a.txt
$ git commit -a -m "Updated the submodule from within the superproject."
$ git push
$ cd ..
$ git add a # There is a gotcha here. Read about it below.
$ git commit -m "Updated submodule a."
So did you commit the new state of your submodule within the parent project before attempting your rebase/merge from said parent project?

Resources