YouTube Video of the seminar: https://youtu.be/ap7rqcD8uPs
Thanks to everyone who was able to attend! --KS
YouTube Video of the seminar: https://youtu.be/ap7rqcD8uPs
Thanks to everyone who was able to attend! --KS
Be sure to install Git version 2.30.0 or higher.
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.
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:
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.
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.
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.
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.
Git part of three essential development skills: documentation, testing, and version control.
core.pager
(cat
or less -FX
)core.editor
(e.g., atom --wait
)core.excludesFile
(~/.gitignore
)status.showUntrackedFiles
(all
)pull.ff
(only
)git log
)alias.*
(custom aliases)diff.colorMoved
(zebra
)diff.colorMovedWS
(allow-indentation-change
)diff.renames
(copy
)git branch
, git switch -c
main
branch (or whatever your default is)dev
)main
, other longer-lived dev branchesgit merge
(public; ff only)git cherry-pick
(private)git rebase
(private)git diff
to catch conflicts before they happencore.editor: https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreeditor (e.g., Atom: atom --wait
; VS Code: code --wait
)
core.excludesFile: https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreexcludesFile
core.pager: https://git-scm.com/docs/git-config#Documentation/git-config.txt-corepager (set to less -FX
to page when needed)
core.whitespace: https://git-scm.com/docs/git-config/2.33.1#Documentation/git-config.txt-corewhitespace ("trailing-space,-space-before-tab,tab-in-indent"
) -> good for anyone who wants to avoid tabs in source code; pretty much anything web
branch.sort: https://git-scm.com/docs/git-config/2.33.1#Documentation/git-config.txt-branchsort
diff.colorMoved: https://git-scm.com/docs/git-config/2.33.1#Documentation/git-config.txt-diffcolorMoved (zebra)
diff.colorMovedWS: https://git-scm.com/docs/git-config/2.33.1#Documentation/git-config.txt-diffcolorMovedWS (allow-indentation-change)
diff.renames: https://git-scm.com/docs/git-config#Documentation/git-config.txt-diffrenames (set to copy
to also detect copied files)
pull.ff: https://git-scm.com/docs/git-config#Documentation/git-config.txt-pullff (set to only
for only fast-forward pulls)
status.showUntrackedFiles: https://git-scm.com/docs/git-config#Documentation/git-config.txt-statusshowUntrackedFiles (set to all
to show individual files)
status.showStash: https://git-scm.com/docs/git-config/2.33.1#Documentation/git-config.txt-statusshowStash (display number of stashed entries with git status
)
Alias your own typos, e.g., git dif
for me
alias.dif = diff
Alias useful, frequent options
alias.dw = diff --color-words
alias.dm = diff --color-moved=plain
alias.ds = diff --staged
alias.l = log
alias.lo = log --oneline
alias.s = status
alias.s = status --short
https://git-scm.com/docs/git-branch
--merged
, --no-merged
; prefixed with --sort
git branch --sort="-authordate"
; see also the branch.sort
config valuehttps://git-scm.com/docs/git-clean
https://git-scm.com/docs/git-log
https://git-scm.com/docs/git-show
Especially short formats (--oneline
) and custom formats. Couple with aliases.
https://git-scm.com/docs/githooks
#! /usr/bin/env sh
STASH_NAME="pre-commit-$(date +%s)"
git stash push -q --keep-index --include-untracked --message $STASH_NAME
FAILED_TESTS=0
trap 'FAILED_TESTS=$((FAILED_TESTS+1))' ERR
# List all test commands to be run, e.g.,
# npm run test
STASHES=$(git stash list -1 | grep -o $STASH_NAME)
if [[ $STASHES == $STASH_NAME ]]; then
git reset --hard -q && git stash apply --index -q && git stash drop -q
fi
if ((FAILED_TESTS == 0)); then
exit 0 # Proceed with the commit
else
echo "Unable to make commit; fix code and stage fixes with \`git add\`"
exit 1 # Halt the commit
fi