Form a 2-person team. Try to find someone who uses the same platform as you (e.g., Windows, Linux, etc.). If you can't, that's fine. If you are the odd-person-out, join a team of 2.
Assign the following roles to the members of your team. If you are in a team of 2, assign the recorder and navigator roles to the same person.
Roles:
-
Driver: Creates and maintains a local git repository.
-
Navigator: Reads instructions and records answers.
3rd person role (if you have a 3-person team):
- Quality Assurance Person: Ensures instructions are being carried out correctly, answers are clear, and looks for ways for the team to work together more effectively.
You will be rotating roles. Your instructor will let you know when to switch roles. Switching roles requires switching computers. So plan accordingly.
- Create and share a shared document (Google Doc, etherpad, etc.) for your team.
- Copy and past this document into your shared document.
Download and install git for your operating system:
Starting a terminal:
-
Windows:
-
git-bash.exe (Linux style commands)
-
git-cmd.exe (Windows style commands)
-
-
Mac OSX: Finder -> Applications -> Utilities -> Terminal.app
-
Linux: will vary depending on your window manager
Run the following commands.
git help
git help -ag
git help init
-
What does
git help
do? -
What does
-ag
causegit help
to do?
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'
WARNING: The name and email you give will be listed on each commit you make. If this repository is ever published, your name and email on every commit will be too. Also, if you are working on a shared computer, you should consider changing this configuration before you walk away.
-
What are these commands doing?
-
What is the purpose of
--global
?
From the command line, run the following commands.
mkdir first_project
cd first_project
-
By default any file that starts with
.
is hidden. How do you display a hidden file? -
Run this command to show the hidden files in the current directory. Are there any?
-
Now run the following command.
git init
-
Check for hidden files again. What was created by
git init
? -
What do you think would happen if you delete
.git
? -
Using your observations to the previous questions, answer the following. You find an old project on your hard drive. You do not remember if it is a under version control. What could you look for to determine if the project is being managed using git?
Use a plain text editor to create names.txt
inside the first_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
-
What kind of information does
git status
report? -
What does
git add names.txt
do? -
What does
git commit -m "Add our names."
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 in alphabetical order.
Run git status
before and after each of these commands.
git add .
git commit Note: Commit will open the vim editor; write a multi-line commit
message, save and quit (press esc and then type :wq).
git log
-
What does
git add .
do? What do you think.
means? -
What does
git commit
(without -m) do? -
If you want to write a more detailed commit message (which is good practice) what command would you use?
-
What does
git log
do?
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
-
Below write each file name under the state that its changes are currently in. Compose a definition for each state.
Staged
Unstaged
Untracked
-
If you run
git commit
what changes will be committed (don't do it)? -
What command do you run to stage changes?
-
What command do you run to unstage changes?
Run the following commands:
git diff
git diff --cached
-
What does
git diff
display? -
What does
git diff --cached
display? -
Formulate a sequence of commands to unstage changes to
names.txt
, and stage the changes tomovies.txt
. Execute your commands and confirm they worked. -
Edit
movies.txt
, change any one of the movies, and save it. Then rungit status
. What do you observe? Explain what you think is going on. -
Delete
names.txt
. Then rungit status
. What do you observe? Explain what you think is going on. -
Rename
movies.txt
tolast-movies
. Rungit status
. Observe and explain. -
Formulate a sequence of commands to stage all changes including the untracked file and commit (with any reasonable message you like). Execute them.
-
In git vernacular,
index
,cache
, andstage
all refer to the same thing. What does it hold? -
Why have a
stage
? Why not just commit all changes since the last commit?
Run the following commands:
git log
git status
git reset --soft "HEAD^"
git log
git status
-
What does
git reset --soft ``"HEAD^"
do?
Run the following commands:
git commit –m "Redo."
git log
git status
git reset --hard "HEAD^"
git log
git status
-
What does
git reset --hard "HEAD^"``
do? -
What is the difference between
--hard
and--soft
? -
What do you think
HEAD
means? -
What do you think
HEAD^
means?
Copyright 2016, Darci Burdge and Stoney Jackson SOME RIGHTS RESERVED
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/ .