Git - track or pull from multiple remotes
I've just started using git (after years of using svn), so I'm probably missing some of the basics.
I am working on a project using the Raspberry Pi. As it happens, one of the devices I use it with seems to have a faulty driver in the kernel, so I'm trying to debug it.
I started with the official RPi core, from here . This kernel is not entirely up to date, although it is not too far behind. I need to use this kernel because according to the documentation it contains some drivers etc. specific to the raspberry pi.
However, since I'm trying to fix something, I think I should start with the very latest possible kernel, which is the wireless-testing repo for the driver I'm looking at.
So what I want to do is apply all the commits that have been made to the wireless test relay but are not yet in the RPi Repo.
If this were possible, it would be ideal if I could restrict the commits I pull from wireless testing to only those that affect a particular directory tree, as I suspect this will reduce the likelihood of conflict of some kind between the two. repos I am pulling from.
Finally, I would ideally like to be able to keep tracking the RPi repo to be able to push from there as well.
What is the best workflow for this?
source to share
You can add them both as remotes and git fetch
from each.
If they are on the same branch, you need to do a merge / rebase and resolve any merge conflicts.
If you need to merge information in two branches, after the two pulls go to the branch you want (with raspberry pie stuff) and do git merge or git rebase (the difference is a topic for a longer conversation) and resolve any conflicts merge as needed.
See also:
http://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows
and
git branch, fork, fetch, merge, rebase and clone, what are the differences?
source to share
Doing direct fetch and merge resulted in a lot of conflicts, none of which affected the driver I'm trying to debug. As stated in the question, I really want to limit the commits that I merge with those that affect this particular driver.
I found a way to do this. The key is the git cherry-pick command .
First add the upstream repo as remote and fetch from it:
git remote add wireless-testing git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git
git fetch wireless-testing
I now have two origin
remotes , (the RPi clone core I originally cloned) and wireless-testing
, a further upstream repo from which I want to pull changes.
Then check out the branch of origin you want to start from (in my case, the RPi branch rpi-3.17.y) and open it from a new local branch:
git checkout rpi-3.17.y
git checkout -b rtlfix
Now, to get a list of commits in the wireless testing repository that are ahead of my branch, but considering only the commits that affect a particular directory tree:
git log wireless-testing/master ^HEAD -- drivers/net/wireless/rtlwifi
This means: "Show the log of commits starting at the beginning of wireless testing / master, and stop when you reach the head of the current local branch, and only looking at the files / dirs under the / net / wireless / rtlwifi directory drivers."
After confirming that this is indeed the list you want, you can apply it with the cherry pick command:
git rev-list --reverse wireless-testing/master ^HEAD -- drivers/net/wireless/rtlwifi | git cherry-pick --stdin
The first command lists the commits in reverse order, and they are passed to the cherry-pick command, which then applies those commits.
There are some caveats with this approach. One, in particular, is that if any of your commitments relies on changes made to other commits that you did not accept, then you will end up with software that won't compile and / or work. Then you may need other commits to fix these issues.
source to share