Basic git
Git is a very powerful, very useful, and complex tool. I strongly encourage you to use it to track all assignments you ever do, if only to become more familiar with it.
Commands we discussed
Creating repositories
git init
- New repositorygit clone $SOURCE
- clone an existing repository, can be local, https, ssh, etc
Creating and managing commits
git add $FILE(s)
- adds a new file to staged changes, or changes to a tracked file to staged changesgit commit
- batches up the stanged changes into a commit, we discussed the -a and -m optionsgit push
- send your new commits back to the remote repository you cloned from (by default)git pull
- get changes from the remote you cloned from (by default), can use –rebaseChecking history and changes
git log
- read the log of all commitsgit blame $FILE
- see what commit last changed what line in the filegit diff $REVISION [$REVISION2]
- see what changed between two revisionsgit checkout $REVISION
- switch your working files to some previous versiongit checkout $BRANCH
- switch to the HEAD of some branchgit checkout $FILE
- revert a file to the state it is in your current branch’s HEADgit branch
- see existing branches or create one
Other git notes
Revisions
Each revision is specified by a unique hash, or by a shortened prefix
of that hash. You can see these in git log
. The current most recent
version in the branch is called HEAD.
You can refer to the ‘parent’ of a revision (the previous one) with
$REVISION~1
or just $REVISION~
for short. $REVISION^1
works
similarly, but has some differences that don’t matter for this course
yet.
.gitignore
Git will look for a special file in the base of your repository
called .gitignore
to determine what files to not track changes
for by default. This is useful to avoid git telling you about all the
temporary or intermediate files generated by the project you are
working on. (Think of the temporary files vim
generates that end in
.swp
).
This file takes a format specified
here. As an example, to ignore
all temporary files vim
tends to generate, you would have:
.*.swp
.*.swo