CS 458 - Week 2 Labs - 11:00 am lab - 2017-08-30
* what is Git?
* a popular distributed version control system
* invented by Linus Torvalds (yes, of Linux fame)
* distributed - you can keep MULTIPLE copies of a
project in multiple locations
* version control - you can check in versions of the
project, and check out not just the latest version,
but previous versions;
* what is GitHub?
* a website -- a web-based hosting service for software
development projects (typically) that use Git
* "Pro Git" 2nd edition (see the link under references)
has a section on installation
* for a Windows box, ONE way (not the only way)
to get a Git installer is to go to:
windows.github.com
* for a Mac OS X box, one way:
mac.github.com
* for (at least some flavors of) Linux, one way:
sudo apt-get install git
* a FEW starter git commands...
* you can check your git version (and/or if you HAVE git)
with:
git --version
* yes, there is a man page!
man git
* a TYPICAL "syntax" for git commands is:
git <desired-git-command> <arguments>
* a CONVENTION is that the man page for a git
command <cmd> is found by typing
man git-<cmd>
(then you run it using
git <cmd> ...
)
* configuring user information in git
use the config command
* you can configure info for your repos at different
levels;
system, global, local
* global - configure this info across all local
repositories
* local - configure this info JUST for (I think?)
a single local repository
* (and there's system -- see Pro Git for more info!)
* typical for global level:
git config --global <info-name> <info-value>
* so, there is some config info you really OUGHT to set up
such as:
user.name - a name identifiable for credit when someone
reviews user history
git config --global user.name "Sharon Tuttle"
user.email - an email address that will be associated
with each history marker (under the "hood")
git config --global user.email "st10@humboldt.edu"
* some are more for convenience;
color.ui - set this to auto if you'd like git
syntax coloring (and your terminal supports it)
core.editor - the name of the text editor program
you'd like to be opened up when git would do that
* you can see your current config values with:
git config --list
* because line feeds can differ for different operating systems,
and your team may have folks using different operating systems:
core.autocrlf
...lets you specify Git's protocol for handling line feeds:
Here are 3 common values:
* false <-- default
* Git does not muck with line feeds on files
either when they come in or when they go out
* true
* Git changes CRLFs to LFs as files are added to
the project object database,
and changes LFs to CRLFs when you grab a file from
the project object database
...this setting is recommended for Windows users
* input
* Git changes CRLFs to LFs as files are added
to the project object database,
but does not change line feeds when you grab a file
from the project object databases
...this setting is generally used for Mac OS X/Linux
/Unix users
so, then set this as desired:
(on nrs-projects, you'd probably want:
git config --global core.autocrlf input
)
* init repo "from scratch"
git init <newproject-name>
<newproject-name> is now a new directory with a .git
subdirectory with Git repo "pieces" within;
* turn an existing directory INTO a Git repo:
* cd TO that directory
* git init
* you need to ADD the current contents to the repo --
add them, then commit those staged adds
git add .
...to stage everything in the current directory
and then
git commit -m "initial import"
* note:
you can see the current status of a repository
using:
git status
* to CLONE a repo from ELSEWHERE
git clone <URL-or-I-think-path>
(the clipboard button on GitHub, when you click the
clone-or-download button, copies that repo's GitHub URL)
* a FEW more useful starter-commands and comments:
* recommended philosophy for commits:
* do small commits often,
BUT!! try to only commit things that compile
and work (leave the repo in a "good" state)
* use "social mechanisms" to get people to do that
* and the typical/recommended work flow:
work, then stage, then commit
stage/add a file that you deem ready using:
git add <filename>
when you want to commit your currently-staged files,
git commit -m "descriptive log message"
^ you see this message when you run
git log
...which lets you see a log of the commits to this repo
* AND what if you like the local commit,
and this happens to be a clone,
and you want to PUSH this local commit
from where you obtained it? <-- by default is called
the origin
git push origin master
* to see changes between a current and committed file
git diff <filename>