Difference between revisions of "EBC Exercise 16 git"

From eLinux.org
Jump to: navigation, search
m (0. Set Up Git: Added host git install instructions)
m (Added Checking out a remote branch)
 
(31 intermediate revisions by 3 users not shown)
Line 4: Line 4:
 
'''[[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.
 
'''[[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.
  
Much of the material here has come from [http://progit.org/book/ Pro Git]. We'll be using [https://github.com/ github] to practice '''git'''ting.
+
Much of the material here has come from [https://git-scm.com/book/en/v2 Pro Git]. We'll be using [https://github.com/ github] to practice '''git'''ting.
 +
 
 +
Here's an [https://www.youtube.com/watch?v=OFkgSjRnay4 O'Reilly Webcast: Git in One Hour]
  
 
== 0. Set Up Git ==
 
== 0. Set Up Git ==
  
Go to [http://help.github.com/set-up-git-redirect github] and follow the directions for installing and setting up git.  No need to set up your own repository right now (unless you want to), I already have one set up for you the play with.
+
If you haven't done so already, go to [[EBC_Exercise_05_Getting_Exercise_Support_Materials#Set_Up_Git]] and follow the directions for setting up git.
 
 
I suggest you do this for both your host computer and your Beagle.  On the Beagle use
 
 
 
beagle$ '''opkg update'''
 
beagle$ '''opkg install git'''
 
beagle$ '''opkg install openssh-keygen'''
 
 
 
The last opkg installs <code>ssh-keygen</code> which is needed to work with github.
 
 
 
On the host
 
 
 
host$ '''sudo apt-get install git-core'''
 
 
 
On my host computer I had to also run
 
 
 
host$ '''ssh-add id_rsa'''
 
 
 
after running <code>ssh-keygen</code> to get <code>ssh -T git@github.com</code> to work.
 
  
 
== 1. Play with git locally ==
 
== 1. Play with git locally ==
  
[http://progit.org Pro Git] has a nice on-line book with lots of good details.  I'll lead you through many parts of it.  The [http://progit.org/book/ first chapter] is '''Getting Started'''.  Here are the topics:
+
[https://git-scm.com/book/en/v2 Pro Git] has a nice on-line book with lots of good details.  I'll lead you through many parts of it.  The [https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control first chapter] is '''Getting Started'''.  Here are the topics:
  
 
<pre>
 
<pre>
Line 42: Line 26:
 
</pre>
 
</pre>
  
I'll cover Git Basics in class and you have already done parts 1.5 and 1.6 to set up for github.  I suggest you take a look at [http://progit.org/book/ch1-6.html Getting Help] and then move on.
+
I'll cover Git Basics in class and you have already done parts 1.5 and 1.6 to set up for github.  I suggest you take a look at [https://git-scm.com/book/en/v2/Getting-Started-Getting-Help Getting Help] and then move on.
  
 
== 2. Git Basics ==
 
== 2. Git Basics ==
Line 58: Line 42:
 
</pre>
 
</pre>
  
There is lots of good material here.  I suggest you work through it all.  Section 2.1 shows how to clone a remote repository.  Try using my repository.
+
There is lots of good material here.  I suggest you work through it all.  Section 2.1 shows how to clone a remote repository.
<pre>
 
git clone git@github.com:MarkAYoder/gitLearn.git
 
</pre>
 
'''gitk''' looks like a nice tool.  Be sure to take a look at it.
 
  
 
=== Questions you should be able to answer after doing chapter 2 ===
 
=== Questions you should be able to answer after doing chapter 2 ===
Line 89: Line 69:
 
I'll work through 3.1 in class.  Read through 3.2 and then do the following exercise.
 
I'll work through 3.1 in class.  Read through 3.2 and then do the following exercise.
  
=== Merging helloWorld.c ===
+
=== Merging helloWorld.py ===
  
 
* clone my repository (The pass phrase is ''Hiapp'')
 
* clone my repository (The pass phrase is ''Hiapp'')
  
  beagle$ '''git clone git@github.com:MarkAYoder/gitLearn.git'''
+
  bone$ '''git clone https://github.com/MarkAYoder/gitLearn.git'''
  beagle$ '''cd gitLearn'''
+
  bone$ '''cd gitLearn'''
  
* Edit <code>helloWorld.c</code> and add a <code>printf</code> with your name on it.
+
* Edit <code>helloWorld.py</code> and add a <code>printf</code> with your name on it.
 
* Compile to be sure it works.
 
* Compile to be sure it works.
* stage and commit <code>helloWorld.c</code>.  You may have to merge.  Keep everyone else's name in the file.
+
* Stage and commit <code>helloWorld.py</code>.  You may have to merge.  Keep everyone else's name in the file.
 
* Push it to the repository.
 
* Push it to the repository.
  
 
Once everyone has done this we should have a file with everyone's name in it.
 
Once everyone has done this we should have a file with everyone's name in it.
  
== Moving from svn ==
+
=== Merge Tools ===
 +
There are a few cool tools to help with merging, notably a graphical diff tool. Many such tools are available and will easily hook up to Git such as kdiff3, meld, vimdiff, etc. (more are listed in ProGit section 1.5). For this example, we're going to use [http://meldmerge.org/ meld].<br>
  
[http://yehudakatz.com/2010/05/13/common-git-workflows/ Here's] a nice article on a common git workflow for those who are moving from svn.
+
You can set up your diff tool by navigating to your .git repository and running:<br>
 +
host$ '''sudo apt update'''
 +
host$ '''sudo apt install meld'''
 +
host$ '''git config --global diff.tool meld'''
  
== Extra Notes ==
+
You can also get rid of the annoying confirmation message by running:<br>
 +
host$ '''git config difftool.prompt false'''
  
The following are extra notes I may clean up later.
+
You can then diff a file in meld using (and background it so you can keep using your shell):<br>
 +
host$ '''git difftool [filename] &'''
 +
Leaving the filename blank should open all files that have been modified.
  
== Access ti/staging ==
+
Lastly, because that command feels really long (and because this class is all about learning how to use Linux more effectively), we're going to add an alias to our .bashrc (or .zshrc, or other .*rc file, depending on what shell you use) file to shorten this.<br>
  
Here is what I did to access the ti/staging stuff.
+
In terminal open up your .bashrc file with your favorite text editor:
 +
host$ '''nano ~/.bashrc'''
  
host$ '''cd ~/oe/openembedded'''
+
This file will have a bunch of stuff that configures your shell, but you're looking for the area that has aliases in it. Add the following lines below the last set of aliases:
host$ '''git remote add gitor git://gitorious.org/angstrom/openembedded.git'''
+
<pre>
host$ '''git fetch gitor'''
+
# alias for Git
host$ '''git checkout gitor/ti/staging -b ti/staging'''
+
alias gdiff='git difftool &'
host$ '''cd ${OETREE}'''
+
</pre>
host$ '''wget http://download.berlios.de/bitbake/bitbake-1.8.18.tar.gz'''
+
This adds gstat and gdiff as commands in bash, so you can type a single command to show the git status or the diff of all modified files in your favorite diff viewer.
host$ '''tar -xvf bitbake-1.8.18.tar.g'''
 
host$ '''gedit source-me.txt'''
 
  
Change
+
== Checking out a remote branch ==
  
PATH=${OETREE}/openembedded/bitbake/bin:${ORG_PATH}
+
Suppose the remote repo has a branch called '''summer2021''' that you want to make local and have the local copy track the upstream copy
  
to
+
bone$ '''git fetch origin summer2021:summer2021'''
 +
bone$ '''git checkout summer2021'''
 +
bone$ '''git push --set-upstream origin summer2021'''
  
PATH=${OETREE}/bitbake-1.8.18/bin:${ORG_PATH}
+
== Moving from svn ==
 
 
Save and quit gedit
 
 
 
host$ '''. source-me.txt'''
 
host$ '''cd ~/oe'''
 
host$ '''mv angstrom-dev angstrom-dev.v0'''
 
host$ '''bitbake console-image'''
 
  
 +
[http://yehudakatz.com/2010/05/13/common-git-workflows/ Here's] a nice article on a common git workflow for those who are moving from svn.
  
 
{{YoderFoot}}
 
{{YoderFoot}}

Latest revision as of 07:50, 2 September 2021

thumb‎ 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.

Much of the material here has come from Pro Git. We'll be using github to practice gitting.

Here's an O'Reilly Webcast: Git in One Hour

0. Set Up Git

If you haven't done so already, go to EBC_Exercise_05_Getting_Exercise_Support_Materials#Set_Up_Git and follow the directions for setting up git.

1. Play with git locally

Pro Git has a nice on-line book with lots of good details. I'll lead you through many parts of it. The first chapter is Getting Started. Here are the topics:

1.1 - About Version Control
1.2 - A Short History of Git
1.3 - Git Basics
1.4 - Installing Git
1.5 - First-Time Git Setup
1.6 - Getting Help
1.7 - Summary

I'll cover Git Basics in class and you have already done parts 1.5 and 1.6 to set up for github. I suggest you take a look at Getting Help and then move on.

2. Git Basics

Chapter is on Git Basics. The topics are:

2.1 - Getting a Git Repository
2.2 - Recording Changes to the Repository
2.3 - Viewing the Commit History
2.4 - Undoing Things
2.5 - Working with Remotes
2.6 - Tagging
2.7 - Tips and Tricks
2.8 - Summary

There is lots of good material here. I suggest you work through it all. Section 2.1 shows how to clone a remote repository.

Questions you should be able to answer after doing chapter 2

  1. How do you stage a file?
  2. How do you view staged and unstaged changes?
  3. How do you view comment history?
  4. You've just committed something and realize you meant to have committed one more file. How do you add that file to the commit you just did?
  5. How do you unstage a file?
  6. How do you unmodify a file?
  7. After running the remote -v how do you tell if a site is read only or read/write?
  8. What's the difference between a lightweight and an annotated tag?

3. Git Branching

Chapter 3 is on branching. Here's the topics from the book:

3.1 - What a Branch Is
3.2 - Basic Branching and Merging
3.3 - Branch Management
3.4 - Branching Workflows
3.5 - Remote Branches
3.6 - Rebasing
3.7 - Summary

I'll work through 3.1 in class. Read through 3.2 and then do the following exercise.

Merging helloWorld.py

  • clone my repository (The pass phrase is Hiapp)
bone$ git clone https://github.com/MarkAYoder/gitLearn.git
bone$ cd gitLearn
  • Edit helloWorld.py and add a printf with your name on it.
  • Compile to be sure it works.
  • Stage and commit helloWorld.py. You may have to merge. Keep everyone else's name in the file.
  • Push it to the repository.

Once everyone has done this we should have a file with everyone's name in it.

Merge Tools

There are a few cool tools to help with merging, notably a graphical diff tool. Many such tools are available and will easily hook up to Git such as kdiff3, meld, vimdiff, etc. (more are listed in ProGit section 1.5). For this example, we're going to use meld.

You can set up your diff tool by navigating to your .git repository and running:

host$ sudo apt update
host$ sudo apt install meld
host$ git config --global diff.tool meld

You can also get rid of the annoying confirmation message by running:

host$ git config difftool.prompt false

You can then diff a file in meld using (and background it so you can keep using your shell):

host$ git difftool [filename] &

Leaving the filename blank should open all files that have been modified.

Lastly, because that command feels really long (and because this class is all about learning how to use Linux more effectively), we're going to add an alias to our .bashrc (or .zshrc, or other .*rc file, depending on what shell you use) file to shorten this.

In terminal open up your .bashrc file with your favorite text editor:

host$ nano ~/.bashrc

This file will have a bunch of stuff that configures your shell, but you're looking for the area that has aliases in it. Add the following lines below the last set of aliases:

# alias for Git
alias gdiff='git difftool &'

This adds gstat and gdiff as commands in bash, so you can type a single command to show the git status or the diff of all modified files in your favorite diff viewer.

Checking out a remote branch

Suppose the remote repo has a branch called summer2021 that you want to make local and have the local copy track the upstream copy

bone$ git fetch origin summer2021:summer2021
bone$ git checkout summer2021
bone$ git push --set-upstream origin summer2021

Moving from svn

Here's a nice article on a common git workflow for those who are moving from svn.




thumb‎ Embedded Linux Class by Mark A. Yoder