Work Locally with Git from the Command Line (Activity)

From Foss2Serve
(Difference between revisions)
Jump to: navigation, search
(next in series comment)
(Suggestions to Open Source Mentors:)
 
(16 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
{| border="1"
 
|-
 
|'''Title''' ||  Git From The Command Line
 
|-   
 
|'''Overview''' ||  Students install and use git from the command line while answering questions about what each command does.
 
  
See [[Git_Activity_3]] for the next in the series.
+
{{Learning Activity Overview
|-
+
|title=
|'''Prerequisite Knowledge''' || 
+
Work Locally with Git from the Command Line
 +
|overview=
 +
Students install and use git from the command line while answering questions about what each command does.
 +
See [[Interactive Visualization with Git]] for the next in the series.
 +
|prerequisites=
 
* Bash skills: manipulate and navigate a filesystem.
 
* Bash skills: manipulate and navigate a filesystem.
 
* Vim skills: edit and exit (with or without changes).
 
* Vim skills: edit and exit (with or without changes).
|-
+
|objectives=
|'''Learning Objectives''' ||  Able to ...
+
* Download, install, and configure git.
 
+
* Download git.
+
* Install git.
+
* Configure git.
+
 
* Configure SSH.
 
* Configure SSH.
 
* Make and commit changes to repository.
 
* Make and commit changes to repository.
* Add new files to repository.
+
* Add and remove files in a repository.
* Remove file from repository.
+
 
* Modify a file and commit the change.
 
* Modify a file and commit the change.
* Stage changes for commit.
+
* Stage and un-stage changes for commit.
* Un-stage changes for commit.
+
 
* Explain the purpose of the stage/cache/index.
 
* Explain the purpose of the stage/cache/index.
 
* Inspect the state of a repository.
 
* Inspect the state of a repository.
 
* Undo a commit.
 
* Undo a commit.
 +
|process skills=
 +
}}
  
|}
+
=== Background ===
  
=== Background: ===
 
 
Is there background reading material?
 
Is there background reading material?
 
* Students can reference http://git-scm.com/doc , though the answers can be found all around the web
 
* Students can reference http://git-scm.com/doc , though the answers can be found all around the web
  
 
Are there other activities the student should have done first?
 
Are there other activities the student should have done first?
* Students may want to understand what SCM is, and why its important via the activity at [[Git_Activity]]
+
* Students may want to understand what SCM is, and why it's important via [[Intro to GitHub (Activity)]]
  
 
What is the rational for this activity?
 
What is the rational for this activity?
* All CS students should be familiar with Git and distributed SCM tools because they allow teams of developers to work together on a single project, at the same time, without stepping on eachother toes. It also forms the basis of most free open source software projects, which have distributed teams of developers that work on various forks and branches of projects. Other SCM solutions (subversion / SVN) cannot handle these scenarios well. Finally, the social and public aspects of coding evidenced by the likes of Github are important for students looking to prove their abilities and experience.
+
* All CS students should be familiar with Git and distributed SCM tools because they allow teams of developers to work together on a single project, at the same time, without stepping on each others' toes. It also forms the basis of most free open source software projects, which have distributed teams of developers that work on various forks and branches of projects. Other SCM solutions (subversion / SVN) cannot handle these scenarios well. Finally, the social and public aspects of coding evidenced by the likes of GitHub are important for students looking to prove their abilities and experience.
  
 
+
=== Directions ===
=== Directions: ===
+
  
 
==== Install Git ====
 
==== Install Git ====
 +
 
Download and install git for your operating system:
 
Download and install git for your operating system:
  
 
* Windows: http://msysgit.github.io/
 
* Windows: http://msysgit.github.io/
 
* Mac OSX or Linux: http://git-scm.com/
 
* Mac OSX or Linux: http://git-scm.com/
 
  
 
==== Setup SSH ====
 
==== Setup SSH ====
 +
 
You might want to setup an SSH key if you plan to work with remote repositories a lot.  
 
You might want to setup an SSH key if you plan to work with remote repositories a lot.  
  
Line 57: Line 51:
  
 
==== Help Yourself ====
 
==== Help Yourself ====
 +
 
Open a terminal (git-bash on Windows) and run the following commands.
 
Open a terminal (git-bash on Windows) and run the following commands.
  
Line 67: Line 62:
 
# What does `git help command` do?
 
# What does `git help command` do?
  
You may use `git help` at any time to help you answer the questions in this
+
You may use `git help` at any time to help you answer the questions in this activity.
activity.
+
  
  
 
==== Identify yourself ====
 
==== Identify yourself ====
Run the following commands, replacing BOGUS NAME and BOGUS@EMAIL with your name
+
 
and email.
+
Run the following commands, replacing BOGUS NAME and BOGUS@EMAIL with your name and email.
  
 
   git config --global user.name 'BOGUS NAME'
 
   git config --global user.name 'BOGUS NAME'
Line 83: Line 77:
  
 
==== Create repository ====
 
==== Create repository ====
 +
 
   mkdir project
 
   mkdir project
 
   cd project
 
   cd project
Line 94: Line 89:
  
 
==== Basic commands ====
 
==== Basic commands ====
 +
 
Use a plain text editor to create `names.txt` inside the `project` folder. Put the names of your team in the file. Save and exit.
 
Use a plain text editor to create `names.txt` inside the `project` folder. Put the names of your team in the file. Save and exit.
  
Line 125: Line 121:
  
 
==== Learn Staging / Tracking ====
 
==== Learn Staging / Tracking ====
 +
 
Do the following:
 
Do the following:
  
Line 161: Line 158:
  
 
==== How to Undo ====
 
==== How to Undo ====
 +
 
   git log
 
   git log
 
   git status
 
   git status
Line 182: Line 180:
  
  
 +
=== Deliverables ===
  
=== Deliverables: ===
 
 
Please hand in your answers to all questions in the Directions.
 
Please hand in your answers to all questions in the Directions.
  
Line 189: Line 187:
  
  
=== Assessment: ===
+
=== Assessment ===
{| border="1"
+
 
 +
{| class="wikitable"
 
|-  
 
|-  
 
|'''Criteria''' ||'''Level 1 (fail)'''||'''Level 2 (pass)'''||'''Level 3 (good)'''||'''Level 4 (exceptional)'''  
 
|'''Criteria''' ||'''Level 1 (fail)'''||'''Level 2 (pass)'''||'''Level 3 (good)'''||'''Level 4 (exceptional)'''  
Line 198: Line 197:
 
|Correct usage || Used incorrect commands || Some correct commands with lazy comments || Mostly Correct commands, occasional comments ||  All Correct commands with contextual comments
 
|Correct usage || Used incorrect commands || Some correct commands with lazy comments || Mostly Correct commands, occasional comments ||  All Correct commands with contextual comments
 
|-
 
|-
|Answers on public git || ||   || ||  Extra points!
+
|Answers on public git (extra points) || No answers on public git || Some answers on public git, but linked incorrectly || All answers on public git, but uses only one large commit ||  All answers on public git, and multiple well-commented commits
 
|-
 
|-
 
|}
 
|}
  
=== Comments: ===
+
=== Comments ===
  
  
=== Additional Information: ===
+
{{Learning Activity Info
{| border="1"
+
|acm unit=
|-
+
SE - Software Engineering / SE Tools and Environments
|'''Knowledge Area/Knowledge Unit''' || SE - Software Engineering from [[ACM_Body_of_Knowledge]]
+
|acm topic=
|-
+
Software configuration management and version control
|'''Topic''' || SE Software Processes, SE Software Project Management, SE Tools and Environments
+
|difficulty=
|-
+
Easy
|'''Level of Difficulty''' || Easy
+
|time=
|-
+
60-90 minutes
|'''Estimated Time to Completion''' || 60-90 mins
+
|environment=
|-
+
|'''Materials/Environment''' ||
+
 
* Access to Internet/Web and web browser
 
* Access to Internet/Web and web browser
 
* Access to posix / unix shell command
 
* Access to posix / unix shell command
 
* Write access to local file system
 
* Write access to local file system
|-
+
|author=
|'''Author''' ||  Stoney Jackson, Nick Yeates
+
Stoney Jackson, Nick Yeates
|-
+
|source=
|'''Source''' || N/A
+
|license=
|-
+
{{License CC BY SA}}
|'''License''' || CC BY-SA 4.0
+
}}
|}
+
 
+
  
 
=== Suggestions to Open Source Mentors: ===
 
=== Suggestions to Open Source Mentors: ===
 +
 
Suggestions for an open source community member who is working in conjunction with the instructor.
 
Suggestions for an open source community member who is working in conjunction with the instructor.
 
* Explain to students what SCM tool they use. If it is not git, explain how it differs.
 
* Explain to students what SCM tool they use. If it is not git, explain how it differs.
 
* The mentor might explain to student what general process or "order of operations" they use when committing code to their project.
 
* The mentor might explain to student what general process or "order of operations" they use when committing code to their project.
  
--------------------
+
[[Category:Learning Activity]]
This work is licensed under a
+
[[Category:Communication and Tools]]
[http://creativecommons.org/licenses/by-sa/4.0/ Creative Commons Attribution-ShareAlike 4.0 International License]
+
[[Category:Git]]
 
+
[[Category:CS2]]
[[File:CC_license.png]]
+
[[Category:Good Draft]]
 
+
[[Category: Learning_Activity]]
+
[[Category: Communication_and_Tools]]
+

Latest revision as of 18:50, 8 March 2017


Title

Work Locally with Git from the Command Line

Overview

Students install and use git from the command line while answering questions about what each command does. See Interactive Visualization with Git for the next in the series.

Prerequisites
  • Bash skills: manipulate and navigate a filesystem.
  • Vim skills: edit and exit (with or without changes).
Learning
Objectives
After successfully completing this activity, the learner should be able to:
  • Download, install, and configure git.
  • Configure SSH.
  • Make and commit changes to repository.
  • Add and remove files in a repository.
  • Modify a file and commit the change.
  • Stage and un-stage changes for commit.
  • Explain the purpose of the stage/cache/index.
  • Inspect the state of a repository.
  • Undo a commit.
Process Skills
Practiced


Background

Is there background reading material?

Are there other activities the student should have done first?

What is the rational for this activity?

  • All CS students should be familiar with Git and distributed SCM tools because they allow teams of developers to work together on a single project, at the same time, without stepping on each others' toes. It also forms the basis of most free open source software projects, which have distributed teams of developers that work on various forks and branches of projects. Other SCM solutions (subversion / SVN) cannot handle these scenarios well. Finally, the social and public aspects of coding evidenced by the likes of GitHub are important for students looking to prove their abilities and experience.

Directions

Install Git

Download and install git for your operating system:

Setup SSH

You might want to setup an SSH key if you plan to work with remote repositories a lot.

See https://help.github.com/articles/generating-ssh-keys


Help Yourself

Open a terminal (git-bash on Windows) and run the following commands.

 git help
 git help -ag
 git help init
  1. What does `git help` do?
  2. What does `-ag` cause `git help` to do?
  3. What does `git help command` do?

You may use `git help` at any time to help you answer the questions in this activity.


Identify yourself

Run the following commands, replacing BOGUS NAME and BOGUS@EMAIL with your name and email.

 git config --global user.name 'BOGUS NAME'
 git config --global user.email 'BOGUS@EMAIL'
  1. What are these commands doing?
  2. What is the purpose of `--global`?


Create repository

 mkdir project
 cd project
 git init
  1. What was created by `git init`?
  2. Any file that starts with `.` is hidden in Linux. How do you display a hidden file in Linux?
  3. What would happen if you delete `.git`?
  4. You find an old project on your hard drive. You do not remember if it is a under version control by git. How can you find out?


Basic commands

Use a plain text editor to create `names.txt` inside the `project` folder. Put the names of your team in the file. Save and exit.

Run `git status` before and after each of these commands.

 git add names.txt
 git commit -m'Add our names.'
 git log
  1. What kind of information does `git status` report?
  2. What does `git add names.txt` do?
  3. What does `git commit -m'Add our names.'` do?
  4. What does `git log do`?


Use a plain text editor to create the following files:

  • `birthdays.txt` - Put your birthdays in this file.
  • `movies.txt` - Put the last movie each of you watched.

Run `git status` before and after each of these commands.

 git add .
 git commit  # You are in vim; write a multi-line commit message, save and quit.
 git log
  1. What does `git add .` do? What do you think `.` means?
  2. What does `git commit` (without -m) do?
  3. If you want to write a more detailed commit message (which is good practice) what command would you use?


Learn Staging / Tracking

Do the following:

  • Modify `names.txt` so that names are listed in _Last, First_ format, one per line.
  • Modify `movies.txt` so they are in reverse alphabetical order by title.
  • Create a new file `foods.txt` that contains your favorite foods (one for each team member).

Run the following commands:

 git add names.txt
 git status
  1. Below write each file name under the state that its changes are currently in. Compose a definition for each state.
    • Staged
    • Unstaged
    • Untracked
  2. If you run `git commit` what changes will be committed (___don't do it___)?
  3. What command do you run to stage changes?
  4. What command do you run to unstage changes?

Run the following commands:

 git diff
 git diff --cached
  1. What does `git diff` display?
  2. What does `git diff --cached` display?
  3. Formulate a sequence of commands to unstage changes to `names.txt`, and stage the changes to `movies.txt`. Execute your commands and confirm they worked.
  4. Edit `movies.txt`, change any one of the movies, and save it. Then run `git status`. What do you observe? Explain what you think is going on.
  5. Delete `names.txt`. Then run `git status`. What do you observe? Explain what you think is going on.
  6. Rename `movies.txt` to `last-movies`. Run `git status`. Observe and explain.
  7. Formulate a sequence of commands to stage all changes including the untracked file and commit (with any reasonable message you like). Execute them.
  8. In git vernacular, `index`, `cache`, and `stage` all refer to the same thing. What does it hold?
  9. Why have a `stage`? Why not just commit all changes since the last commit?


How to Undo

 git log
 git status
 git reset --soft HEAD^
 git log
 git status
  1. What does `git reset --soft HEAD^` do?
 git commit -m'Redo'
 git log
 git status
 git reset --hard HEAD^
 git log
 git status
  1. What does `git reset --hard HEAD^` do?
  2. What is the difference between `--hard` and `--soft`?
  3. What do you think `HEAD^` means?
  4. What do you think `HEAD` means?


Deliverables

Please hand in your answers to all questions in the Directions.

Bonus points for those who type their answers up and link to them on a public git repository!


Assessment

Criteria Level 1 (fail) Level 2 (pass) Level 3 (good) Level 4 (exceptional)
# of Answers 20 of 36 26 of 36 30 of 36 36 of 36
Correct usage Used incorrect commands Some correct commands with lazy comments Mostly Correct commands, occasional comments All Correct commands with contextual comments
Answers on public git (extra points) No answers on public git Some answers on public git, but linked incorrectly All answers on public git, but uses only one large commit All answers on public git, and multiple well-commented commits

Comments

ACM BoK
Area & Unit(s)

SE - Software Engineering / SE Tools and Environments

ACM BoK
Topic(s)

Software configuration management and version control

Difficulty

Easy

Estimated Time
to Complete

60-90 minutes

Environment /
Materials
  • Access to Internet/Web and web browser
  • Access to posix / unix shell command
  • Write access to local file system
Author(s)

Stoney Jackson, Nick Yeates

Source
License

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License

CC license.png


Suggestions to Open Source Mentors:

Suggestions for an open source community member who is working in conjunction with the instructor.

  • Explain to students what SCM tool they use. If it is not git, explain how it differs.
  • The mentor might explain to student what general process or "order of operations" they use when committing code to their project.
Personal tools
Namespaces
Variants
Actions
Events
Learning Resources
HFOSS Projects
Evaluation
Navigation
Toolbox