Git: Merge test repository into master repository - ruby-on-rails

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

Related

Pull request creation was canceled when having two branches?

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

Using git pull properly

I am new to git so please bear with me. I have a rails application on my local machine that I am experimenting with and pushing to the master branch periodically. It works at the moment, but I have fallen behind, and now I am many commits behind the master.
$ git branch
* master
$ git status
On branch master
Your branch is behind 'origin/master' by 27 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working tree clean
However, when I use git pull and then start rails, my application breaks with a precompiler error. So I am forced to use git --reset to go back to the local commit before I used git pull.
What is the right way to get around this issue and merge with the latest changes on the master branch? Would one use git --rebase in this case?
Try
git stash
git pull origin master
And once it updates, git stash apply to reapply your local changes
Since nobody has stated this clearly yet: You ask
What is the right way to get around this issue and merge with the latest changes on the master branch?
When you do git pull that does merge the remote changes into your current branch. Whether you would choose to do a rebase instead of a merge (per your other question) is a separate issue, but the default behavior is to combine the two sets of changes (local and remote).
More precisely, by default git pull does a fetch followed by a merge. The exact merge operation depends on configuration and on command-line options, but in a typical configuration where origin/master is upstream of master, saying
git pull
will merge origin/master into master.
So why the errors?
One possibility is that there were merge conflicts. If that happens, git will tell you. If you say git status in this condition, it will tell you that there's a merge in progress and it will indicate which paths (files) need conflict resolution.
Another possibility is that the changes don't conflict (in that they don't affect the same region of the same file) but still don't work properly together. That you would simply have to debug.

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?

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.

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