Some git questions

Firmware/software/electronics/mechanics
Post Reply
alex
Expert
Posts: 137
Joined: Mon Feb 18, 2013 11:36 am
Location: Germany

Some git questions

Post by alex »

Hey community,

I developed some feature for the CF 1.0 firmware and pushed it from my local repo to my firmware fork on GitHub into the feature branch origin/sonar-mb1242.
In the meantime, the CF 2.0 was released and therefore the original Bitraze firmware repo holds the additional branch crazyflie2. I'd like to copy that branch to my own fork.

I added the remote upstream pointing to the original Bitcraze repo. This is also essential for updating origin/master from the original Bitcraze repo upstream/master.


This is what I did so far to get the upstream/crazyflie2 branch into my local repo:

Code: Select all

git fetch upstream
git checkout --track upstream/crazyflie2
Now I have a local branch crazyflie2 tracking upstream/crazyflie2. Next step would be pushing this new local branch to my fork origin/crazyflie2.

Am I on the right track? How do I push the new local branch to my fork (origin)?
How do I tell the local branch crazyflie2 to track the recently pushed origin/crazyflie2 later on and not upstream/crazyflie2 anymore?

I hope I expressed myself clearly.


Thank you.
-alex
Last edited by alex on Tue Feb 03, 2015 10:07 pm, edited 1 time in total.
alex
Expert
Posts: 137
Joined: Mon Feb 18, 2013 11:36 am
Location: Germany

Re: Some git questions

Post by alex »

Here is my solution since I think others might be in the same situation.

alex wrote:How do I push the new local branch to my fork (origin)?

Code: Select all

git push origin crazyflie2
alex wrote:How do I tell the local branch crazyflie2 to track the recently pushed origin/crazyflie2 later on and not upstream/crazyflie2 anymore?

Code: Select all

git branch crazyflie2 --set-upstream-to origin/crazyflie2
That's all. I know there are git commands that can do these things at once, but I tried to keep it simple for myself. ;)


Remember: the commands above and those in my last post need upstream to be pointing at the original Bitcraze repo. This can by done by adding it as an additional remote:

Code: Select all

# List the current remotes (origin is your fork on GitHub)
$ git remote -v
origin  https://github.com/alexriegel/crazyflie-firmware.git (fetch)
origin  https://github.com/alexriegel/crazyflie-firmware.git (push)

# Set the new remote upstream to the original Bitcraze repo
$ git remote add upstream https://github.com/bitcraze/crazyflie-firmware.git

# Verify new remote
$ git remote -v
origin    https://github.com/alexriegel/crazyflie-firmware.git (fetch)
origin    https://github.com/alexriegel/crazyflie-firmware.git (push)
upstream  https://github.com/bitcraze/crazyflie-firmware.git (fetch)
upstream  https://github.com/bitcraze/crazyflie-firmware.git (push)
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Some git questions

Post by tobias »

Thanks for the information alex!
alex
Expert
Posts: 137
Joined: Mon Feb 18, 2013 11:36 am
Location: Germany

Re: Some git questions

Post by alex »

Ok, just got another one:

How can I take my work on the dedicated sonar-mb1242 branch and place it on top of the crazyflie2 branch?

Rebasing sonar-mb1242 onto crazyflie2 doesn't seem to work:

Code: Select all

bitcraze@bitcraze-vm:~/projects/crazyflie-firmware-alex$ git checkout sonar-mb1242
Switched to branch 'sonar-mb1242'
Your branch is up-to-date with 'origin/sonar-mb1242'.
bitcraze@bitcraze-vm:~/projects/crazyflie-firmware-alex$ git rebase crazyflie2
First, rewinding head to replay your work on top of it...
Applying: Adjusted headline sizes.
Using index info to reconstruct a base tree...
M	README.md
Falling back to patching base and 3-way merge...
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Failed to merge in the changes.
Patch failed at 0001 Adjusted headline sizes.
The copy of the patch that failed is found in:
   /home/bitcraze/projects/crazyflie-firmware-alex/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
What is the correct way to port my changes on the CF 1.0 firmware to the 2.0 code base?

Thanks again.
alex
poizone
Member
Posts: 59
Joined: Thu Feb 05, 2015 3:59 am
Location: Ohio, USA

Re: Some git questions

Post by poizone »

It looks like your only problem is that the readme.md files aren't merging properly. Just skip the error to finish the rebase, and manually merge the readme files if you changed it. It should work just fine. This error specifically means that the same line of your file has been changed by two different commits, and git doesn't know which to apply.

More info in the Git help: https://help.github.com/articles/resolv ... it-rebase/
One day our flies will drown out the sun in an autonomous Skynet of whirring motors and blinking lights.
alex
Expert
Posts: 137
Joined: Mon Feb 18, 2013 11:36 am
Location: Germany

Re: Some git questions

Post by alex »

poizone wrote:It looks like your only problem is that the readme.md files aren't merging properly. Just skip the error to finish the rebase, and manually merge the readme files if you changed it. It should work just fine. This error specifically means that the same line of your file has been changed by two different commits, and git doesn't know which to apply.

More info in the Git help: https://help.github.com/articles/resolv ... it-rebase/
Thanks for your reply, but this error shows up for many files. If I think about it, it makes sense since the files from the crazyflie2 branch diverged a lot from the ones of my sonar-mb1242 branch which is originally based on the CF 1.0 code base. So I don't think this would be the most comfortable way. Unless someone tells me something else... :

I decided to port my sonar code manually to the existing crazyflie2 branch. This way I am able to eliminate some commits that only exist because I coded some lines without actually thinking about them in detail the first time (I2C addresses for example).

So I switched to the crazyflie2 branch and imported my work from the sonar-mb1242 branch by checking out the mb1242 driver source, HAL and header files:

Code: Select all

git checkout crazyflie2
git checkout sonar-mb1242 drivers/src/mb1242.c
git checkout sonar-mb1242 drivers/interface/mb1242.h
git checkout sonar-mb1242 hal/src/sonar.c
git checkout sonar-mb1242 hal/interface/sonar.h
After this, the main part of my sonar development is in my working directory on top of the branch crazyflie2. Rebuilding the function calls to these files in stabilizerInit and stabilizerTask is just a breeze.

After I get my work done for proper CF 2.0 integration I will just have to do an initial push including all the local changes. It might be helpful to do this on an additional branch, again.

Hope this will help if someone is faced with the same issues as I was.

See you.
Post Reply