How push approved commits from one branch to another branch in bitbucket - 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?

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 to update after GitHub pull request is merged?

I have an issue understanding the work flow on GitHub.
First I fork someones repository.
I clone the repository locally( on my computer)
I create a branch called Sample101 and make changes
I push branch Sample101 to my GitHub account
I create a pull request
The person I created a pull request Merges Sample101 Branch to his Master Branch.
The question is, How do I update my forked/clone after that person merges/updates his master branch? I just want my master copy to be up to date.
In your local repository cloned from your Github repository (which is the fork you have push rights), add the remote for the original repository
git remote add upstream <original remote url>
Now pull, or fetch merge, whichever you're more comfortable with
git checkout master
git pull upstream master
Now push up to your fork
git push origin master

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

code push to heroku not working

I want to push code on heroku that is on gihub
I used the following command
git push heroku mybranch:master
The error is
To https://github.com/user/lyricle-new.git
! [rejected] lyricle-frt-backend -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/user/app.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Used the command git pull as mentioned in hint the response was Already up-to-date.
What could be the reasons behind this error? and is this the correct way to push on heroku
By doing git push heroku mybranch:master, you are telling git to take your local mybranch branch and merge it with the remote master branch (remotely stored on your heroku repo).
You get an error because master is ahead of mybranch in terms of commits.
Consider this example:
master: --------b---------m---------
mybranch:........\-c--c--/...........
At some point, you branch (b) master into mybranch, commit (c) some code to the branch, and merge (m) it back to master.
Now consider this example:
master: --c-----b---c-----m---c--
mybranch:........\-c--c---/.......
It is pretty much the same scenario but while you were committing code to mybranch, someone updated master by committing some other code. If you were to merge back mybranch into master, you would risk causing conflicts between your code and the new code contained in master, thus Git refuses to do the merge. First, you have to update your local branch with the new version of master and then only Git will allow you to push.
In short:
- git pull heroku master:mybranch
- resolve potential conflicts
- commit modified files
- git push heroku mybranch:master
Now about Heroku, you are supposed to always push code like this: git push heroku master (considering you are on the master branch locally). What you should do to avoid things like git push heroku mybranch:master is, when you finish working on a branch, always merge your changes to master and then (after verifying that everything is working) push master to heroku.
See this resource for a simple git workflow that seem to be what you are looking for: https://www.atlassian.com/git/workflows#!workflow-feature-branch
Everything is centralized in master eventually, and you can then regularly push master to heroku (ideally you would push once for every version of your app)
From the hints it seems that you have not pushed your latest changes to your remote repository.if you have done a pull and pushed again maybe you have removed files in your local repository that you did not remove in your remote repository.try doing a git add --all and then commit and push the changes.

Pushing a branch to a remote repository in git

I'm trying to update the 3-2-stable branch on my fork of the Ruby on Rails project. So after cloning rails, I initially did a git checkout -b my_branch remotes/origin/3-2-stable. Then I made my changes. Then I added my fork as a remote repository with git remote add my_fork git#github.com:myusername/rails.git. Does a git push my_fork my_branch update the 3-2-stable branch only in my_fork? Is there something special I need to do?
Does a git push my_fork my_branch update the 3-2-stable branch only in my_fork?
Yes it will. It won't affect any other repo.
Note that the 3-2-stable on your fork won't be impacted either: a new branch my_branch will be created on your fork to reflect your local branch.
But if you want to push/pull that branch from the repo my_fork, then this would make it easier:
git push -u my_fork my_branch
See "What exactly does the “u” do? “git push -u origin master” vs “git push origin master”" for more on setting the upstream branch of a local branch.

Resources