Skip to content

Instantly share code, notes, and snippets.

@karlstolley
Last active Jan 23, 2022
Embed
What would you like to do?
Setup instructions and agenda for IIT College of Computing Git Seminar, January 20, 2022

Git Installation

Be sure to install Git version 2.30.0 or higher.

MacOS/OS X Installation

A lot of developer technologies require XCode’s command-line tools, but they are useful in their own right. To install them, you’ll need to pull up the Terminal app on your Mac. The easiest way to do this is through Spotlight Search: click the magnifying glass in the upper right-hand corner of your Mac, and start typing Terminal; click the result that appears labeled as an Application.

You’ll have a small white window that pops up, with a line that most likely has the name of your computer followed by a colon, tilde, and dollar-sign, e.g., janes-mac:~ $. There’ll also be a cursor, which may or may not blink.

Type xcode-select --install (note the space before the two hyphens) and hit the Return/Enter key. (You might be prompted for your admintrator password.) You should see a some output fly by, unless you've installed XCode previously. In that case, you'll get an error informing you that your command-line tools are already installed. Once the script has finished running and you see the dollar-sign prompt again, type git version and press return. You should see git version 2.30.1 (Apple Git-130), or a similar number, output in the Terminal window.

To easily install the very latest version of Git, follow the instructions below for installing Homebrew and then run:

$ brew install git

Don't forget to configure Git once you've got the latest version installed.

Windows Installation

Download the Windows installer for Git and double-click the downloaded file’s icon to install it; it’ll probably be in your Downloads folder.

Walk through the Git Setup Wizard, making the following changes from the defaults:

  1. On the Select Components screen:
  • Select "On the Desktop" under Additional Icons
  • De-select "Windows Explorer Integration"
  1. On the Adjusting your PATH environment screen:
  • Choose "Use Git from Git Bash only*"
  1. On the Configuring the line ending conversions screen:
  • Choose "Checkout as-is, commit as-is"

Git Setup will then complete the installation; it takes a few minutes. Click Finish when it's done.

Look for the Git or git-bash icon on your desktop. Double-click it, and type git version into the terminal window that opens. You should see output like git version 2.32.0 or some similar number.

Linux Installation

If you're running Linux, Git may already be on your system. Run git version in your terminal shell to see if there's any output. If you get a "Command not found" error, Google around for the preferred method to install or compile Git on your Linux distribution, preferably with its package manager so you automatically receive updates along with the rest of your system.

Basic Git Configuration

You'll need to open a terminal window (MacOS/Linux) or a Windows shell (Windows), and type the following commands. Replace YOUR NAME and YOUR@EMAIL with the actual name and email you use.

$ git config --global user.name "YOUR NAME"
$ git config --global user.email "YOUR@EMAIL"

When you've run those commands, run git config --global --list and you should see your name and email. If you do not, re-run the commands above to fix any mistakes you've made.

As of Git 2.28.0, it is essential to configure Git to use a custom default branch name. The default branch had been master, which Git, GitHub, and the wider industry are moving away from because of its historically racist connotations. main is now the preferred name for the default branch, and we will use that in this course. To set main as your default branch for all new repositories that you create, simply run:

$ git config --global init.defaultBranch "main"

If for whatever reason you cannot install at least Git 2.28.0, your best bet is to create an alias for yourself, such as git new, which you will need to use in place of git init:

$ git config --global alias.new '!git init && git symbolic-ref HEAD refs/heads/main'

If you have old repositories that you'd like to convert from master to main, check out this excellent post's instructions.

Finally, you need to tell Git which merge strategy to use in case you end up interacting with a remote branch that has changes you don't yet have locally--and local changes that are not yet on the remote.

To start with, you can tell Git to use the default merge strategy:

$ git config --global pull.rebase false

Eventually, you'll remove that value and set pull.ff to only instead, but we'll cover that in the Git seminar. Go with false on pull.rebase for now.

Once you've done all of that configuration, check that you've set everything correctly by running:

$ git config --global --list

You'll see output for each of your configuration values. If you've made any mistakes, just rerun the git config --global commands above with the correct value.

Git Seminar Agenda

Join Karl Stolley, Associate Professor of Information Technology and Management, for a fun and lively hands-on Git seminar on Thursday, January 20, 2022 from 7pm to 9pm CST (America/Chicago). Whether you're brand-new to Git or a seasoned user, this seminar has something for everyone: You'll tune your Git configuration to suit your workflow and development environment. You'll learn how to expertly craft atomic commits by leveling up on your diffing abilities and writing your commits in a professional style. You'll gain confidence in collaborating with others using remote repositories hosted on GitHub and elsewhere, and you'll discover techniques for organizing your work and experimenting across multiple branches. You'll also learn how to effortlessly manage the trickier sides of Git, including reconciling divergent branches, fixing merge conflicts, and rewriting a repository's history before you share your work with the rest of the world.

Starting Lines

  • Ground rules tonight: ask questions, at any time (use the text chat)
  • Files, organization, POSIX-compliant CLI

Introduction

Git part of three essential development skills: documentation, testing, and version control.

  1. Kicking the tires on the base configuration
  2. Setting up a repository locally
  3. A quick commit
  4. Talking to GitHub (SSH key setup)
  5. Referencing and pushing to a remote

Some More Essential Configuration

  • core.pager (cat or less -FX)
  • core.editor (e.g., atom --wait)
  • core.excludesFile (~/.gitignore)
  • status.showUntrackedFiles (all)
  • pull.ff (only)

Mindful Git Practice

  • Beware the “cheat sheet” approach to Git. Because there really is no cheating Git :)
  • Git’s a lot of things, including a learning tool. That includes learning about your own habits, both good and bad.
  • Anatomy of a typical Git workflow (work, save, status, diff, craft, commit)
  • Anatomy of a commit (diff/patch, commit message > SHA-1 hash)
  • Repository history (git log)

Even More Essential Configuration

  • alias.* (custom aliases)
  • diff.colorMoved (zebra)
  • diff.colorMovedWS (allow-indentation-change)
  • diff.renames (copy)

Working Across Multiple Branches

  • Developing a mental model of your project, and very precise habits to keep things sane and organized.
  • Multiple timelines: git branch, git switch -c
  • Don’t commit on the main branch (or whatever your default is)

Branch Life-Cycles

  • Long-lived development branches (dev)
  • Shorter-lived feature branches
  • Getting feature work onto the main, other longer-lived dev branches

Changing History

  • Project history (long, public, stable) vs. feature history (short, private, unstable)
  • Moving commits from one branch to another
  • Squashing small commits
  • Breaking up large commits

Untangling Some Related Commands

  • git merge (public; ff only)
  • git cherry-pick (private)
  • git rebase (private)

Fixing Conflicts

  • Use git diff to catch conflicts before they happen
  • Um, they still happen. Okay!
  • Local branches
  • Remote branches
  • Fetching and diffing against remotes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment