Git is a powerful source code control system that allows developers to store their source code, collaborate, and manage changes. For this tutorial, Git uses some terminology that we need to remember:
.git directory
at the root of your working tree. You do not need to edit anything in
there directly, only through a git command on
the command line.add command
into your local repository. When you commit, you need to write a
descriptive message of the changes, and Git also records the timestamp.In this exercise, we will be focusing on how to use Git on the command line, including creating a repository, adding files, committing files, and pushing your changes to a remote repository.
Git
is also how we will be submitting assignments in this class. You will be
creating one personal repository for this entire course. As you work, you will
be asked to make many commits at logical times. When you are ready to submit an
assignment, then you will push your changes to /pushbox
hamilton.se.rit.edu using your
SE account and password. A few notes: Shift + Insert. swen250
. The command is: mkdir swen250swen250 using the cd command. If you are in your home directory you type cd swen250. You can verify
your location by typing pwd to print the working directory. A few notes regarding
directories: ./ ../. So to go up one directory use cd ../ ~ (tilde)
represents your home directory. Thus, your swen250 directory can be
called ~/swen250 bash Tab will auto-complete
to known commands and directories .profile file in your home directory to automatically use the bash shell.
This file should contain exec /bin/bashSource
control systems are great for breaking up your work into logical tasks. Carefully follow the
instructions below:
git config command for changing user.name and user.email, like this:
$ git config --global user.name "Chuck Norris"
$ git config --global user.email "cxn9999@rit.edu"
$ git config --global color.ui true
~/swen250, type git init .
ONLY
RUN THIS COMMAND ONCE!!!Initialized empty Git repository in (your home directory)/swen250/.git/
name.txt. nano. Type nano name.txt to create
and edit the file, use hotkeys shown at the bottom - (e.g. ^X means Ctrl+X) vim as the course moves forward. Check
out our resources page for more information on learning different
editors. name.txt, write your
name (so the instructor knows who you are). git
status.
You should get output like this: # On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add..." to include in what will be committed)
#
# name.txt
nothing added to commit but untracked files present (use "git add" to track)
nano .gitignore create and
edit the file and add the following contents. Be careful that your copy/paste
does not ruin the formatting:
Copy starting from line below:
# This file will prevent Git from adding files that match the following
# patterns to the repository. If you need to add a file anyway, you can use
# `git add -f [file]`
# Text editor swap files
*.swp
*.swo
*~
# Compiled binary files
*.o
<Copy up to line above>
Note that git will not ignore a file that was already tracked before a rule was added to this file to ignore it. In such a case the file must be un-tracked, usually with git rm --cached filename
git add .. Running git status now gives us the following
output: # On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached..." to unstage)
#
# new file: name.txt#
git commit vim text editor
for you to enter your commit message. (If you would rather use nano to
edit your commit messages, then run git config --global core.editor "nano"). Git
commit messages have this convention: For this class, the most important
element is a well-written subject line. "A few changes" is the worst
possible commit message - be descriptive without being verbose (50 characters
is short - this parenthetical is 49).
Write a descriptive message for adding the name file, such as "Recording
my name for grading".
[master (root-commit) 5d859e9] Recording my name for grading
1 file changed, 1 insertion(+)
create mode 100644 name.txt
/pushbox/make-my-pushbox.sh
swen250-NN summer2168 CHANGE NN to be your section (01 through 04)! ONLY RUN THIS SCRIPT ONCE!!!
If everything in the script worked, then you should get the output that looks
If everything in the script worked, then you should get the output that looks
something like this:
Initialized empty Git repository in /pushbox/swen250-01-spring2165-cxn9999-54cd8f737bcb5e8b33916193f56d6e94/
Success!
git
push pushbox master. The output looks like this: Counting objects: 3, done.
Writing objects: 100% (3/3), 236 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /pushbox/swen250-01-fall2151-cxn9999-54cd8f737bcb5e8b33916193f56d6e94
* [new branch] master -> master
Here's the typical workflow we want you to use.
git status. Commit or
remove any changes you might have forgot to deal with before (i.e. start
with a clean working tree). git status.For this exercise, let's use our FizzBuzz code into our working tree.
git status - to make
sure everything has been committed (should say "# On branch master
nothing to commit (working directory clean)")git push pushbox
master
- if it says "Everything up-to-date", you have everything
pushed and submittedgit rm or git add -A . to record that deletion. git
add . && git commit && git push pushbox master
Also, in bash, you can use the up arrow to bring that command back up quickly. If you realize you don't want to commit partway through, then exit your text editor with an empty commit message and everything aborts safely.
/pushbox