120 Git basics [1d]

Updated . Posted . Visible to the public.

Git Show archive.org snapshot is our version control system. This lesson covers the everyday moves — committing, branching, merging, working with a remote — and the habits that make your history pleasant to review.

Important

Work on this lesson in teacher mode.

Learning goals

  • You can explain where a change lives at each stage — working copy, staging area, local repository, remote — and how it moves between them.
  • You can record work in a local repository: stage, commit, and inspect history and diffs.
  • You can work with branches: create, switch and merge them, and explain what a fast-forward merge is.
  • You can put uncommitted changes aside and get them back (stash).
  • You can synchronize with a remote repository over SSH, and explain the difference between fetching and pulling.
  • You write commits a colleague can review: one change per commit, a subject line that says what and why.
  • Your Git configuration follows our config example (identity, SSH key, default branch, pull behaviour).
  • You can browse a repository's history in a viewer (tig is our default) and create repositories and merge requests on code.makandra.de.
  • You have a GitHub account and know our rules for private accounts on work PCs.

Tip

Always clone repositories with SSH. Otherwise, you would have to send your git credentials to the remote server every time you interact with it.
Image

Resources

Read what's new to you, skim what's familiar, skip what you already master. Stop when you can meet the learning goals.

Your agent can also generate an overview, a tutorial or an explanation for anything here, tailored to what you already know. Just ask.

Pick one introduction

Go deeper

Our setup and conventions

Reference

Exercises

Understanding git concepts

Try and explain:

  • Why do we use Git at all?
  • What is the "workspace"?
  • What is the "index" or "staging area"?
  • What is the "stash"?
  • What is the difference between a local and a remote repository?
  • What is a "Fast Forward"?

Play around on code.makandra.de

In an earlier lesson you built a searchable address book, in a directory of your exercises repository. Give it a repository of its own: you keep working on it in the next lessons, and it is a good excuse to click through the GitLab interface.

  • Create a repository in your personal namespace (/firstname.lastname), e.g. address-book.
  • Move the address book directory out of your exercises repository and into a clone of the new one.
  • Add and commit the files
  • Create a branch and make some small changes there
  • Write the commit message as if a colleague had to review it: a subject that says what and why (see "How to Write a Git Commit Message" in the resources)
  • Push changes to the server
  • Make a merge request from the branch to your main
  • Accept the merge request
  • Look at the resulting history with tig

Play around on github.com

  • Sign up
  • Create a repository in your personal namespace (/username)
  • Add some files, push them
  • Delete the repository when done

Important

Read our rules for private GitHub accounts (see Resources) before you sign up.

Profile picture of Henning Koch
Henning Koch
Last edit
Henning Koch
Attachments
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra Curriculum (2015-07-07 15:04)