Crash course on Git

Brief introduction to Git basics: Why and how to use it

Allan T. Souza

What is Git?

  • Is a software that acts as a version control system used to track changes in files.
  • Helps in collaboration and maintaining the history of project files.
  • Allows you to revert to previous versions if needed.

Why To Use Git?

  • Track changes over time.

  • Facilitates collaboration.

  • Enables branching for independent development.

  • Increases security by enabling back-up and redundancy.

Still wondering…

This is important for “computer” people, not for me

This is important for “computer” people, not for me

  • Git is useful for managing version control in any project, from data processing, visualization and analysis to writing reports, manuscripts and much more.

I work mostly by myself, so there is no point of using Git

I work mostly by myself, so there is no point of using Git

  • Even when working alone, Git helps you keep your work organized, experiment safely, and back up your files.

Nobody is interested in my work

Nobody is interested in my work

  • Sharing our codes ensures reproducibility, which is essential for science.
  • We cannot know that our work is really not relevant to anyone, it might be more relevant than we think.

Requirements to Have Git Running

  • Operating system agnostic

    • Linux

    • Mac

    • Windows

Requirements to Have Git Running

  • Installation is required
    • UH computers might have it installed by default
  • Installing git in different operating systems:
    • Linux: Install via package manager (e.g., sudo apt-get install git).
    • macOS: Install via Homebrew (brew install git) or Xcode Command Line Tools.
    • Windows: Download installer.
  • Git website: https://git-scm.com/

Using Git

Configure User Identity

  • Set your name and email (used in commits):
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
  • HTTPS

    • Use your username and password when prompted.
  • SSH

    • Instructions to set up the SSH can be found here.
  • You can also access the contents by the ZIP file

    • Download Zip file

Git Hosting Services

Accessing the information from a GitHub repository

  • Select the option you are willing to work with (HTTPS, SSH, GitHub CLI).

  • Go to the directory where you want to work in your computer, and clone the repository (make a local copy of it)
git clone git@github.com:haapaniemi/KVJ.git

Creating a GitHub Repository

  • Go to github.com and log in to your account (if you don’t have it, sign in).

  • Create a New Repository

    Click the + icon in the top-right corner.

    • Select New repository from the dropdown menu.

Creating a GitHub Repository

  • Repository Details

    • Add a name for your repository,

    • Add a brief description of your repository.

    • Visibility

      • Choose Public or Private.

Git most common workflow and commands

  • Update Your Local Repository

  • Make Changes

    • Create, modify, or delete files in your working directory.
  • Stage Changes

    • Add new or modified files to the staging area

Git most common workflow and commands

  • Commit Changes

    • Record your staged changes with a descriptive message

  • Share Changes

  • Check Repository Status

Git basic commands

  • git init - Create an empty Git repository or reinitialize an existing one.

  • git clone - Clone a repository into a new directory.

  • git add - Add file contents to the index.

  • git commit-m "message" - Record changes to the repository with an associated message.

  • git push - Update remote refs along with associated objects.

  • git pull - Fetch from and integrate with another repository or a local branch.

Git basic commands

Supporting Materials

Online Courses

Interactive Tutorials/Games