EBC Exercise 16 git Workshop Version
Embedded Linux Class by Mark A. Yoder
git is a distributed revision control system with an emphasis on being fast. It was initially designed and developed by Linus Torvalds for Linux kernel development. The purpose of this lab is to get hands on experience with git to learn how it works and how to use it.
This is the workshop version of the exercise. It assumes git is already installed and the repository is already cloned.
Much of the material here has come from Pro Git. We'll be using github to practice gitting.
Update the git repository
Always before you start work on a git project, make sure you have the current version from github.
beagle$ cd ~/gitLearn beagle$ git pull
Play with git locally
- Edit
helloWorld.c
and add aprintf
with your name on it. - stage and commit
helloWorld.c
. You may have to merge. Keep everyone else's name in the file. - Push it to the repository
Here's how it is done.
beagle$ gedit helloWorld.c beagle$ gcc helloWorld.c Make sure the file compiles and runs OK. beagle$ './a.out beagle$ git status What's the status of helloWorld? beagle$ git add beagle$ git status What's the status now? beagle$ git commit -m "Put your own comment here" beagle$ git status What's the status now? beagle$ git push This will send your repository to gethub
If the last git push give you error, it means someone else has changed the file on the repository and you need to get the new version before you can push. Do this
beagle$ git pull
If you run into an fatal HTTP request failed error you might have generate a key using ssh-keygen and add it to you SSH keys on your github. To install ssh-keygen do the following:
beagle$ opkg install openssh-keygen
To access the file created by the keygen cat the file using the following command
beagle$
git will try to merge the new version of the file with your version. It it's successful all you have to do is.
beagle$ gedit helloWord.c Do this to be sure the file looks OK. beagle$ gcc helloWorld.c beagle$ ./a.out If it doesn't compile edit and fix it. beagle$ git add beagle$ git commit -m "Another descriptive comment here" beagle$ git push
If you aren't lucky, git won't be able to merge and it will tell you so. Edit the file as above and look for <<<<<< , this will mark the places git didn't know how to handle. Fix them and remove the lines with <<<<<< and repeat the steps above.
If you are lucky, no one else has changed the file while you were working on it. If not, repeat the above steps.
Wait a while and do a git pull to see if anyone else has changed the repository.
Moving from svn
Here's a nice article on a common git workflow for those who are moving from svn.
Embedded Linux Class by Mark A. Yoder