git pull from a github repository fork gives conflicts - ruby-on-rails

I have forked rails git://github.com/rails/rails.git at github. My forked repository is at git://github.com/waseem/rails.git. I want to test out some patches submitted by other users to rails mainline. Lets say I want to test out code in migration_status branch at git://github.com/joelmoss/rails.git.
Lets say I
master $ git remote add joelmoss git://github.com/joelmoss/rails.git. and
master $ git remote add mainline git://github.com/rails/rails.git.
I have been pulling from rails mainline into my master.
master $ git pull mainline master
According to http://guides.rubyonrails.org/contributing_to_ruby_on_rails.html#testing-patches I should create a local topic branch and pull in changes from joelmoss/migration_status. So I,
master $ git checkout -b migration_status Create a local topic branch.
And when I do:
migration_status $ git pull joelmoss migration_status
I get a large number of conflicts. I also tried migration_status $ git pull --rebase joelmoss migration_status but I still get conflicts.
In the case of pull --rebase, I think (correct if wrong), git is trying to apply my local changes on top of changes fetched from joelmoss/migration_status. Ideally it should do the opposite. To consider this option, I did following.
master $ git fetch joelmoss
master $ git checkout -b joel_migration_status joelmoss/migration_status and
joel_migration_status $ git rebase master it still gave me lots of conflicts.
How do I pull in patches submitted to one of my local topic branches w/o getting conflicts? I can not resolve those conflicts as I do not know much about what code to keep what not to.

In this case, it looks like joelmoss/migration_status is based off of 3.1.0, which split from mainline/master back in May. So if you merge you're trying to reconcile 4 months worth of development by everyone, in branches that appear to never have been intended to merge.
What you want to do is base your local changes on 3.1 as well. That doesn't guarantee to remove all conflicts, but at least it should be ones you are aware of because it's code you changed directly.
git checkout -b master-3-1 master
git rebase --onto joelmoss/migration_status mainline/master master-3-1

Related

How to get Bitbucket/Git URL for a specific branch?

I use bitbucket but I need to pull a specific branch using the git url.
My git url look like:
https://bitbucket.com/scm/<project_name>/<repo_name>.git
I need to pull specific branch though so I tried:
https://bitbucket.com/<username>/scm/<project_name>/<repo_name>/branch/<branch_name>
https://bitbucket.com/<project_name>/<repo_name>/branch/<branch_name>
https://bitbucket.com/scm/<project_name>/<repo_name>/branch/<branch_name>
https://bitbucket.com/scm/<project_name>/<repo_name>.git#<branch_name>
I keep getting errors like 501 or not found
The goal is to connect my repository to Informatica https://docs.informatica.com/data-integration/powercenter/10-4-0/application-service-guide/model-repository-service/version-control-for-the-model-repository-service/configure-and-synchronize-a-model-repository-after-changing-vers.html
I'm not 100% sure I understand what you are trying to do.
If you have already cloned your repo, you can pull a specific branch using the url instead of the name of your remote.
# You normally pull with this command:
git pull origin my_branch
# You can pull using the URL instead:
git pull bitbucket.com/scm/<project_name>/<repo_name>.git my_branch
If you have not yet cloned your repo, you can clone a specific branch:
git clone --branch my_branch bitbucket.com/scm/<project_name>/<repo_name>.git
I need to pull specific branch though so I tried:
Those all seem like reasonable ways to do it for http urls, Git uses a way that doesn't depend on any specific server's url format
git remote add somename u://r/l -t branch
and you can repeat the -t branch option as many times as there are branches you'd like to track, or just let it default to all branches.
If you don't want tags, add --no-tags. I usually don't for sideband repos like this, I count it as a minor wart, probably too late or anyway not worth it to fix, that git remote add doesn't default to this for any remote not named origin.
Then
git fetch somename
brings the tracking refs up to date.

Heroku rollback and pulling older release

I did a mistake in the code and pushed it in to heroku master. I am not able to identify the problem in the code I have locally. I did a heroku rollback to previous version - it worked and previous version is visible on heroku.
However I am struggling to pull the code (as heroku clone:app name gives me an old code). I tried heroku releases to get the release number which I then used for git pull heroku af5c366b, however getting err:
fatal: Couldn't find remote ref af5c366b
How can the code be restored?
I am completely now to Heroku.
You should be able to simply run...
$ git checkout af5c366b
Which should bring you to a "detached head" state with this helpful message..
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
Once you checkout the branch you can merge that branch into master.
$ git checkout master
$ git merge new-branch-name

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.

Pull changes from github to local rails files

So I know how to update the repository with my files (the master one at least). And I know I can create a local branch with
$ git checkout -b [branch_name]
but that only creates it on the local git...how do i checkout a branch from the master on github and also overwrite files in my app directory, so I can update my project with the work of other people
Do you mean to ask, how to reset master on your local machine to that of the master on the origin?
If so:
Fetch all remote/origin changes and then hard reset your local master to origin/master's head:
$ git checkout master
$ git fetch --all
$ git reset --hard origin/master

Deploying a Re-Written Github/Heroku App

I have an app that is live on Heroku/Github, but recently completely rebuilt it from scratch - I want to keep the old repository name, what is the best way to replace the live code with the new code?
Slight variation from Michael's answer:
git branch -M master old_master
git rm -rf .
git checkout --orphan master
git remote add version2 "/path/to/new_version/.git"
git pull version2 master
(as usual, back up everything first)
If you are using git1.7.2+, you can use git checkout --orphan:
Similar to -b, --orphan creates a new branch, but it starts without any commit.
After running "git checkout --orphan newbranch", you are on a new branch "newbranch", and the first commit you create from this state will start a new history without any ancestry.
When creating a branch whose trees have no resemblance to the ones from the original branch, it may be easier to start work on the new branch by untracking and removing all working tree files that came from the original branch, by running a 'git rm -rf .' immediately after running "checkout --orphan".
You avoid having two different history on the same branch, with an abrupt change at one specific commit.
Instead you keep several root branches with different history in it.
But that means rewriting the history of commits of master, which isn't that bad considering you only need the previous history for reference and archive only.
cd old_version
git rm -rf .
git commit -m "Removing the old code"
git remote add version2 "/path/to/new_version/.git"
git pull version2 master
That should fully preserve both histories and have the new version be the HEAD of orginal repo. I would recommend backing up repos up before you try this.

Resources