Automated Version Control


  • Version control is like an unlimited ‘undo’.
  • Version control also allows many people to work in parallel.

Navigating Files and Directories


  • The file system is responsible for managing information on the disk.
  • Information is stored in files, which are stored in directories (folders).
  • Directories can also store other directories, which then form a directory tree.
  • pwd prints the user’s current working directory.
  • ls [path] prints a listing of a specific file or directory; ls on its own lists the current working directory.
  • cd [path] changes the current working directory.
  • Most commands take options that begin with a single -.
  • Directory names in a path are separated with / on Unix, but \ on Windows.
  • / on its own is the root directory of the whole file system.
  • An absolute path specifies a location from the root of the file system.
  • A relative path specifies a location starting from the current location.
  • . on its own means ‘the current directory’; .. means ‘the directory above the current one’.

Working With Files and Directories


  • cp [old] [new] copies a file.
  • mkdir [path] creates a new directory.
  • mv [old] [new] moves (renames) a file or directory.
  • rm [path] removes (deletes) a file.
  • * matches zero or more characters in a filename, so *.txt matches all files ending in .txt.
  • ? matches any single character in a filename, so ?.txt matches a.txt but not any.txt.
  • Use of the Control key may be described in many ways, including Ctrl-X, Control-X, and ^X.
  • The shell does not have a trash bin: once something is deleted, it’s really gone.
  • Most files’ names are something.extension. The extension isn’t required, and doesn’t guarantee anything, but is normally used to indicate the type of data in the file.
  • Depending on the type of work you do, you may need a more powerful text editor than Nano.

Setting Up Git


  • Use git config with the --global option to configure a user name, email address, editor, and other preferences once per machine.

Creating a Repository


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

Tracking Changes


  • git status 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).
  • git add puts files in the staging area.
  • git commit saves the staged content as a new commit in the local repository.
  • Write a commit message that accurately describes your changes.

Exploring History


  • git diff displays differences between commits.
  • git checkout recovers old versions of files.

Ignoring Things


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

Remotes in GitHub


  • A local Git repository can be connected to one or more remote repositories.
  • Use the SSH protocol to connect to remote repositories.
  • git push copies changes from a local repository to a remote repository.
  • git pull copies changes from a remote repository to a local repository.

Hosting Websites on GitHub


  • “GitHub Pages is a static site hosting service that takes files in various formats (Markdown, HTML, CSS, JavaScript, etc.) straight from a repository on GitHub, runs them through its website engine Jekyll, builds them into a website, and publishes them on the Web”
  • “By convention, if you create a branch called gh-pages in your repository, it will automatically be published as a website by GitHub”
  • “You can configure any branch of a repository to be used for website (it does not have to be gh-pages)”
  • “GitHub publishes websites on special URLs formatted as ‘https://GITHUB_USERNAME.github.io/REPOSITORY_NAME’”

Collaborating


  • git clone copies a remote repository to create a local repository with a remote called origin automatically set up.

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.