Git Reference Guide

Introduction to Git

Git is a distributed version control system used to track changes in source code during software development.

Configuration

git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"

Basic Git Commands

  • git init: Initializing a Repository

  • git clone <repository_URL>: Cloning a Repository

  • git add <filename>: Adding Changes

  • git add -A: Adding ALL Changes

  • git commit -m "Commit Message": Committing changes

  • git status: Checking status of current git repo

  • git log: Viewing Commit History

Branching and Merging

  • git branch <new-branch>: create a new branch based on the current HEAD
  • git branch <new-branch> <base-branch>: create a new branch based on some existing one
  • git switch <branch-name>: switch to
  • git merge <branch_name>: merge into current branch
  • git branch -d <branch_name>: delete

Remote Repositories

Remote repositories are shared locations for storing version controlled code that often allow for collaboration. Examples are GitHub and GitLab.

  • git remote -v: See linked remote repositories (verbose)
  • git remote add <remote_repository_name> <remote_URL>: add a remote repository
  • git push -u <remote_repository_name> <branch_name>: push changes to a remote repository
  • git pull <remote_repository_name> <branch_name>: pull changes from a remote repository
  • git pull <remote_repository_name> <branch_name> -a: pull all changes from a remote repository, including new branches

Note: If you only have one remote repository called origin, you do not need to include the ; git will use origin by default in most cases.

Additional Resources