Git

Git is a distributed version control system (VCS) that tracks changes in project files and supports collaborative workflows with lightweight branching and remotes.

Installation and Setup

Install the CLI with your platform tools, then set your identity:

Windows PowerShell
PS> winget install --id Git.Git -e --source winget
PS> git --version
PS> git config --global user.name "Your Name"
PS> git config --global user.email "you@example.com"
PS> git config --global init.defaultBranch main
Shell
$ sudo apt-get update && sudo apt-get install -y git
$ git --version
$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"
$ git config --global init.defaultBranch main
Shell
$ brew install git
$ git --version
$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"
$ git config --global init.defaultBranch main

Key Features

  • Distributed model with full local history, offline commits, and cheap clones.
  • Fast branching and merging that enable short lived feature branches and code review.
  • Staging area that lets you craft commits by selecting exact changes.
  • Remote workflows for collaboration on services like GitHub and GitLab with push, fetch, and pull.
  • Advanced tools such as worktrees, submodules, sparse checkout, and signed tags.

Usage

Start a repository and make your first commit:

Shell
$ git init
$ echo "# Awesome Python Project" > README.md
$ git add README.md
$ git commit -m "Initial commit"

Connect to a remote and publish:

Shell
$ git remote add origin https://example.com/your/repo.git
$ git push -u origin main

Create and switch branches, then merge:

Shell
$ git switch -c feature/api
$ # Edit files
$ git add -A
$ git commit -m "Add API"
$ git switch main
$ git merge feature/api

Keep a clean history while syncing:

Shell
$ git fetch origin
$ git rebase origin/main

Inspect changes and history:

Shell
$ git status
$ git diff
$ git log --oneline --graph --decorate --all

Stash work in progress and restore files:

Shell
$ git stash -u
$ git stash pop
$ git restore path/to/file          # discard work in a file
$ git restore --staged path/to/file # unstage a file

Tag a release and push tags:

Shell
$ git tag -a v1.0.0 -m "First release"
$ git push --follow-tags

Use a Python friendly .gitignore to avoid committing build artifacts and environments.

Tutorial

Introduction to Git and GitHub for Python Developers

What is Git, what is GitHub, and what's the difference? Learn the basics of Git and GitHub from the perspective of a Pythonista in this tutorial.

basics tools

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated Dec. 12, 2025