Version Control with Git: Git Cheatsheets for Quick Reference

Key Points

Automated Version Control
  • Version control is like an unlimited Undo button.

  • Version control also allows many people to work in parallel.

Setting Up Git
  • Use GitHub Desktop’s dialogue prompts to configure a user name and email address. Customize which text editor you use under GitHub Desktop’s Preferences pane.

Creating a Repository
  • You can initialize a git repository by clicking on New Repository under the File dropdown or typing Ctrl-N.

  • Git stores all of its repository data in the .git directory.

Tracking Changes
  • Atom’s Git extension (typically displayed in the right pane of the editor) shows the status of a repository.

  • Files can be stored in a project’s working directory (which users see), the staging area (where the next commit is being built up) and the local repository (where commits are permanently recorded).

  • Staging files indicates that you want them to be tracked. Leaving files unstaged allows you to not track changes you don’t care about

  • Committing saves staged content in the local repository, preserving the state of your project at a particular point in time. This is similar to taking a photograph.

  • Write a commit message that accurately describes your changes.

Ignoring Things
  • The .gitignore file tells Git what files to ignore.

Git Remotes
  • A local Git repository can be connected to one or more remote repositories.

  • Use the HTTPS protocol to connect to remote repositories until you have learned how to set up SSH.

  • Pushing copies changes from a local repository to a remote repository.

  • Fetching checks for changes in the history of a remote repository and copies data about those historical events to a local repository.

  • Pulling copies file changes from a remote repository to a local repository.

Exploring History
  • Differences between commits can be examined using the History tab in GitHub Desktop. You can look at diffs on the GitHub website side by side by right-clicking on a commit and then clicking on View on GitHub.

  • You can examine the state of your repository at a particular time by clicking Browse files when comparing differences between files on GitHub’s website.

  • You can recover old versions of files by reverting changes.

Collaborating
  • Copying a remote repository to create a local repository is called cloning.

  • Collaborators can either have direct access to a repository, or make changes that are mediated by pull request reviews.

Conflicts
  • Conflicts occur when two or more people change the same lines of the same file.

  • The version control system does not allow people to overwrite each other’s changes blindly, but highlights conflicts so that they can be resolved.

Putting It All Together
  • The concepts described in previous sections all contribute to a typical version control workflow.

Licensing
  • Ensure that your manuscript or source code is assigned a license from the onset to avoid issues down the line.

  • Ensure that you have the legal right to assign a license before assigning one.

  • Multiple websites list very good options for open source licenses. Unless you are actively consulting with a lawyer, it is best to use one of these licenses or another established license.

Citation
  • Add a CITATION file to a repository to explain how you want your work cited.

Hosting
  • Projects can be hosted on university servers, on personal domains, or on public forges.

  • Rules regarding intellectual property and storage of sensitive information apply no matter where code and data are hosted.

Git Cheatsheets for Quick Reference

Glossary

changeset
A group of changes to one or more files that are or will be added to a single commit in a version control repository.
commit
To record the current state of a set of files (a changeset) in a version control repository. As a noun, the result of committing, i.e. a recorded changeset in a repository. If a commit contains changes to multiple files, all of the changes are recorded together.
conflict
A change made by one user of a version control system that is incompatible with changes made by other users. Helping users resolve conflicts is one of version control’s major tasks.
fetch
The act of downloading summaries of events in the Git history without actually downloading the changes themselves. HTTP
The Hypertext Transfer Protocol used for sharing web pages and other data on the World Wide Web.
initialization
The step in the Git workflow where you tell it to start watching for changes in files.
merge
(a repository): To reconcile two sets of changes to a repository.
pull
(a repository): To copy changes from a remote repository to a local repository.
push
(a repository): To copy changes from a local repository to a remote repository.
protocol
A set of rules that define how one computer communicates with another. Common protocols on the Internet include HTTP and SSH.
remote
(of a repository) A version control repository connected to another, in such way that both can be kept in sync exchanging commits.
repository
A storage area where a version control system stores the full history of commits of a project and information about who changed what, when.
resolve
To eliminate the conflicts between two or more incompatible changes to a file or set of files being managed by a version control system.
revision
A synonym for commit.
SHA-1
SHA-1 hashes is what Git uses to compute identifiers, including for commits. To compute these, Git uses not only the actual change of a commit, but also its metadata (such as date, author, message), including the identifiers of all commits of preceding changes. This makes Git commit IDs virtually unique. I.e., the likelihood that two commits made independently, even of the same change, receive the same ID is exceedingly small.
staging
The step in the Git workflow where you tell Git which changes you want to keep and which changes you don’t want to keep track of. Changes that you have not told Git to keep are said to be unstaged.
SSH
The Secure Shell protocol used for secure communication between computers.
timestamp
A record of when a particular event occurred.
version control
A tool for managing changes to a set of files. Each set of changes creates a new commit of the files; the version control system allows users to recover old commits reliably, and helps manage conflicting changes made by different users.