Skip to content

github-community-projects/periodic-table-of-git-merge-2025

The Periodic Table of Git πŸ§ͺ

Reimagining Git fundamentals through the lens of the iconic periodic table, transforming complex commands into easy chemical elements.

Welcome to the companion repository for the "Periodic Table of Git" talk at Git Merge 2025! This repository contains practical examples and explanations of Git commands organized like elements in a periodic table.

πŸ”¬ The Git Elements

Just like the periodic table organizes chemical elements by their properties, we'll organize Git commands into logical families that share similar behaviors and use cases.


🧱 Basic Elements (Group 1)

The fundamental building blocks of version control

git init (Element: In)

Initializes a new Git repository, creating the foundation for version control.

git init                    # Initialize a new repository
git init --bare            # Create a bare repository (for servers)
git init --template=<path>  # Use a custom template

When to use: Starting any new project or adding version control to existing code.

πŸ“– Official Documentation

git add (Element: Ad)

Stages changes for the next commit, moving files from working directory to staging area.

git add file.txt           # Stage a specific file
git add .                  # Stage all changes in current directory
git add -A                 # Stage all changes in entire repository
git add -p                 # Interactively stage chunks of changes

When to use: Preparing changes before committing, controlling exactly what gets included in each commit.

πŸ“– Official Documentation

git commit (Element: Cm)

Creates a snapshot of staged changes with a descriptive message.

git commit -m "Add user authentication feature"     # Commit with message
git commit --amend -m "Fix typo in commit message" # Amend last commit
git commit -S                                       # Sign commit with GPG
git commit --allow-empty -m "Trigger CI build"     # Empty commit

When to use: Saving your work at logical points, creating checkpoints in development.

πŸ“– Official Documentation

git status (Element: St)

Shows the state of the working directory and staging area.

git status              # Full status
git status -s           # Short status
git status --porcelain  # Machine-readable format

When to use: Before commits to see what will be included, checking current state of repository.

πŸ“– Official Documentation

git config (Element: Cf)

Get and set repository or global options.

git config --global user.name "Your Name"     # Set global username
git config --global user.email "[email protected]"  # Set global email
git config --list                             # List all config values
git config user.name                          # Get specific config value

When to use: Setting up Git for first time, configuring user information, customizing Git behavior.

πŸ“– Official Documentation

git stash (Element: Sa)

Temporarily save uncommitted changes.

git stash                       # Stash uncommitted changes
git stash pop                   # Apply most recent stash and remove it
git stash list                  # List all stashes
git stash drop                  # Delete most recent stash

When to use: Switching branches with uncommitted changes, temporarily saving work in progress.

πŸ“– Official Documentation

git rm (Element: Re)

Remove files from working tree and index.

git rm file.txt                 # Remove file from working tree and index
git rm --cached file.txt        # Remove from index only, keep in working tree
git rm -r directory/            # Remove directory recursively
git rm "*.log"                  # Remove all .log files

When to use: Deleting files from version control, cleaning up project structure.

πŸ“– Official Documentation

git mv (Element: Mv)

Move or rename files, directories, or symlinks.

git mv oldname.txt newname.txt  # Rename file
git mv file.txt folder/         # Move file to folder
git mv folder1/ folder2/        # Rename directory
git mv src/*.js lib/             # Move multiple files

When to use: Renaming files, moving files to different directories, reorganizing project structure.

πŸ“– Official Documentation


🧭 Navigation Elements (Group 2)

Moving through branches, commits, and repository states

git checkout (Element: Co)

Switches between branches, commits, or restores files from different states.

git checkout main                    # Switch to main branch
git checkout -b feature/new-ui       # Create and switch to new branch
git checkout HEAD~2                  # Move to 2 commits back
git checkout -- file.txt            # Restore file from last commit
git checkout v1.0.0 -- config.json  # Get file from specific tag

When to use: Switching contexts, creating branches, restoring files, exploring history.

πŸ“– Official Documentation

git branch (Element: Br)

Lists, creates, or deletes branches in your repository.

git branch                          # List local branches
git branch -a                       # List all branches (local + remote)
git branch feature/api-update       # Create new branch
git branch -d feature/completed     # Delete merged branch
git branch -D feature/experimental  # Force delete unmerged branch
git branch -m old-name new-name     # Rename branch

When to use: Managing parallel development streams, organizing features and fixes.

πŸ“– Official Documentation

git switch (Element: Sw)

Modern alternative to checkout for switching branches (Git 2.23+).

git switch main                    # Switch to existing branch
git switch -c feature/dashboard    # Create and switch to new branch
git switch -                       # Switch to previous branch
git switch --detach HEAD~5        # Detach HEAD at specific commit

When to use: Cleaner alternative to git checkout for branch operations.

πŸ“– Official Documentation

git tag (Element: Tg)

Creates, lists, or deletes tags to mark specific points in history.

git tag v1.0.0                           # Create lightweight tag
git tag -a v1.0.0 -m "First release"     # Create annotated tag
git tag -l "v1.*"                        # List tags matching pattern
git tag -d v0.9.0                        # Delete local tag
git push origin v1.0.0                   # Push tag to remote
git push origin :refs/tags/v0.9.0       # Delete remote tag

When to use: Marking releases, important milestones, or stable points in development.

πŸ“– Official Documentation

git reflog (Element: Rl)

Show reference log - a history of where HEAD and branches have been.

git reflog                      # Show HEAD reflog
git reflog --all                # Show all references reflog
git reflog branch-name          # Show specific branch reflog
git reset --hard HEAD@{2}       # Reset to previous HEAD position

When to use: Recovering lost commits, understanding recent branch/HEAD movements, debugging repository state.

πŸ“– Official Documentation


🌐 Remote Elements (Group 3)

Connecting and synchronizing with other repositories

git remote (Element: Rm)

Manages connections to remote repositories.

git remote                               # List remotes
git remote -v                            # List remotes with URLs
git remote add origin https://github.com/user/repo.git  # Add remote
git remote set-url origin [email protected]:user/repo.git  # Change URL
git remote rename origin upstream        # Rename remote
git remote remove old-remote            # Remove remote

When to use: Setting up repository connections, managing multiple remotes, changing repository URLs.

πŸ“– Official Documentation

git push (Element: Ps)

Uploads local commits to a remote repository.

git push origin main                    # Push main branch
git push -u origin feature/new-ui      # Push and set upstream
git push origin :old-branch-name       # Delete remote branch
git push origin main --force-with-lease # Safer force push
git push origin --tags                 # Push all tags
git push origin :refs/tags/v1.0.0     # Delete remote tag

When to use: Sharing your work, updating remote repositories, publishing releases.

πŸ“– Official Documentation

git pull (Element: Pl)

Fetches and merges changes from a remote repository.

git pull                        # Pull from tracked remote branch
git pull origin main            # Pull from specific remote/branch
git pull --rebase              # Pull with rebase instead of merge
git pull --ff-only             # Only fast-forward, fail if merge needed

When to use: Getting latest changes from team members, staying synchronized with remote.

πŸ“– Official Documentation

git fetch (Element: Ft)

Downloads objects and refs from remote repository without merging.

git fetch                       # Fetch from default remote
git fetch origin               # Fetch from specific remote
git fetch --all                # Fetch from all remotes
git fetch --prune              # Remove remote-tracking branches that no longer exist

When to use: Getting remote changes without affecting working directory, preparing for manual merge.

πŸ“– Official Documentation

git clone (Element: Cl)

Clone a repository into a new directory.

git clone https://github.com/user/repo.git    # Clone via HTTPS
git clone [email protected]:user/repo.git        # Clone via SSH
git clone --depth 1 <url>                     # Shallow clone
git clone -b feature <url>                    # Clone specific branch

When to use: Starting work on an existing project, creating local copies of remote repositories.

πŸ“– Official Documentation


πŸ“š History Elements (Group 4)

Exploring and understanding repository history

git log (Element: Lg)

Shows commit history with various formatting options.

git log                                    # Standard commit log
git log --oneline                         # Compact one-line format
git log --graph --decorate --all          # Visual branch representation
git log origin/main..HEAD --merges --oneline  # Merges between branches
git log -p                                # Show patches (diffs)
git log --since="2 weeks ago"            # Time-based filtering
git log --author="John Doe"               # Author-based filtering

When to use: Understanding project history, finding specific changes, preparing release notes.

πŸ“– Official Documentation

git diff (Element: Df)

Shows differences between commits, branches, files, or working directory.

git diff                         # Working directory vs staging area
git diff --staged               # Staging area vs last commit
git diff HEAD^ HEAD             # Last change (previous commit vs current)
git diff main feature/branch    # Compare branches
git diff v1.0.0 v1.1.0         # Compare tags
git diff --name-only            # Just show changed file names

When to use: Reviewing changes before commit, comparing versions, understanding what changed.

πŸ“– Official Documentation

git show (Element: Sh)

Displays information about Git objects (commits, tags, trees).

git show                        # Show last commit
git show HEAD~2                 # Show specific commit
git show v1.0.0                 # Show tag information
git show --name-only            # Show only changed file names

When to use: Examining specific commits, understanding what a tag contains.

πŸ“– Official Documentation

git blame (Element: Bl)

Shows who last modified each line of a file and when.

git blame file.txt              # Show blame for entire file
git blame -L 10,20 file.txt     # Show blame for specific lines
git blame -w file.txt           # Ignore whitespace changes

When to use: Understanding code ownership, finding when bugs were introduced, code archaeology.

πŸ“– Official Documentation

git rev-list (Element: Rv)

List commit objects in reverse chronological order.

git rev-list HEAD               # List all commits from HEAD
git rev-list --count HEAD       # Count commits from HEAD
git rev-list --since="1 week ago" HEAD  # Recent commits
git rev-list --author="John" HEAD       # Commits by author

When to use: Scripting Git operations, advanced history analysis, building custom tools.

πŸ“– Official Documentation


πŸ” Debugging Elements (Group 5)

Finding problems and understanding issues

git bisect (Element: Bs)

Uses binary search to find the commit that introduced a bug.

git bisect start                # Start bisecting
git bisect bad                  # Mark current commit as bad
git bisect good v1.0.0          # Mark known good commit
git bisect run make test        # Automate bisect with test command
git bisect reset               # End bisect session

When to use: Finding regression bugs, identifying when problems were introduced, debugging complex issues.

πŸ“– Official Documentation

git rerere (Element: Rr)

Records and reuses merge conflict resolutions automatically.

git config rerere.enabled true     # Enable rerere
git rerere                          # Show recorded resolutions
git rerere diff                     # Show current resolution
git rerere forget path/to/file     # Forget resolution for file

When to use: Working with long-lived branches, repetitive merge conflicts, complex rebasing scenarios.

πŸ“– Official Documentation


πŸ—οΈ Advanced Elements (Group 6)

Powerful tools for complex workflows

git submodule (Element: Sm)

Manages repositories inside other repositories.

git submodule add https://github.com/user/lib.git lib    # Add submodule
git submodule init                                       # Initialize submodules
git submodule update                                     # Update submodules
git submodule update --remote                           # Update to latest remote
git submodule foreach git pull origin main              # Update all submodules

When to use: Including external libraries, managing dependencies, modular project structure.

πŸ“– Official Documentation

git reset (Element: Rs)

Resets current HEAD to specified state, powerful but dangerous.

git reset --soft HEAD~1         # Undo commit, keep changes staged
git reset --mixed HEAD~1        # Undo commit and unstage (default)
git reset --hard HEAD~1         # Undo commit and discard changes
git reset file.txt              # Unstage specific file

When to use: Undoing commits, unstaging files, cleaning up local history before pushing.

⚠️ Warning: --hard permanently destroys uncommitted changes!

πŸ“– Official Documentation

git rebase (Element: Rb)

Re-applies commits on top of another base tip, rewriting history.

git rebase main                 # Rebase current branch onto main
git rebase -i HEAD~3           # Interactive rebase last 3 commits
git rebase --continue          # Continue after resolving conflicts
git rebase --abort             # Abort rebase operation

When to use: Cleaning up commit history, squashing commits, maintaining linear history.

πŸ“– Official Documentation

Git Squash* (Element: Sq)

Squashing is done through interactive rebase, not a standalone command

Combines multiple commits into a single commit, cleaning up history.

git rebase -i HEAD~3           # Interactive rebase to squash last 3 commits
# In the editor that opens:
# pick abc1234 First commit
# squash def5678 Second commit  # Change 'pick' to 'squash' or 's'
# squash ghi9012 Third commit   # This will combine all into first commit

git reset --soft HEAD~3 && git commit  # Alternative: soft reset + new commit

When to use: Cleaning up feature branch before merging, combining related commits, preparing clean history.

πŸ“– Official Documentation

git worktree (Element: Wt)

Manages multiple working trees attached to the same repository.

git worktree add ../feature feature/branch    # Create new worktree
git worktree list                             # List all worktrees
git worktree remove ../feature                # Remove worktree
git worktree prune                            # Clean up stale references

When to use: Working on multiple branches simultaneously, testing different versions, parallel development.

πŸ“– Official Documentation

git revert (Element: Rt)

Create new commits that undo the changes from previous commits.

git revert HEAD                 # Revert the last commit
git revert abc1234              # Revert specific commit
git revert --no-edit HEAD       # Revert without opening editor
git revert HEAD~3..HEAD         # Revert range of commits

When to use: Undoing changes in shared branches, maintaining clean history, safe rollback of features.

πŸ“– Official Documentation


🀝 Collaboration Elements (Group 7)

Working with others and sharing code

git send-email (Element: Se)

Sends patches via email for code review and contribution.

git send-email [email protected] *.patch     # Send patch files
git send-email --compose [email protected]        # Compose email

When to use: Contributing to projects that use email workflows, Linux kernel development, traditional patch-based collaboration.

πŸ“– Official Documentation

git request-pull (Element: Rp)

Generates a summary of pending changes for pull requests.

git request-pull origin/main https://github.com/user/repo.git feature

When to use: Creating formal pull request descriptions, summarizing changes for maintainers.

πŸ“– Official Documentation


🧹 Maintenance Elements (Group 8)

Keeping your repository healthy and optimized

git gc (Element: Gc)

Garbage collection - optimizes repository by packing and cleaning up.

git gc                          # Standard garbage collection
git gc --aggressive             # More thorough optimization
git gc --prune=now             # Remove unreachable objects immediately

When to use: Regular maintenance, after large operations, optimizing repository size.

πŸ“– Official Documentation

git fsck (Element: Fs)

File system check - verifies repository integrity.

git fsck                        # Check repository integrity
git fsck --full                 # Complete check including pack files

When to use: Diagnosing repository corruption, verifying after recovery operations.

πŸ“– Official Documentation

git fast-export (Element: Fe)

Export repository history in a format suitable for importing.

git fast-export --all > repo.dump        # Export entire repository
git fast-export main > branch.dump       # Export specific branch
git fast-export --since="2023-01-01" HEAD > recent.dump  # Export recent history

When to use: Repository migration, creating backups, filtering repository history, converting between VCS.

πŸ“– Official Documentation

git fast-import (Element: Fi)

Import repository history from fast-export stream.

git fast-import < repo.dump      # Import repository from dump
cat backup.dump | git fast-import  # Import from pipe
git fast-import --quiet < data.dump  # Import silently

When to use: Repository migration, restoring from backups, importing from other VCS, repository reconstruction.

πŸ“– Official Documentation

git prune (Element: Pr)

Prune all unreachable objects from the object database.

git prune                       # Prune unreachable objects
git prune --dry-run             # Show what would be pruned
git prune --expire=now          # Prune all unreachable objects immediately

When to use: Manual repository cleanup, reclaiming disk space, maintenance after complex operations.

πŸ“– Official Documentation

git clean (Element: Cn)

Remove untracked files from the working tree.

git clean -f                    # Remove untracked files
git clean -fd                   # Remove untracked files and directories
git clean -n                    # Dry run - show what would be removed
git clean -fX                   # Remove only ignored files

When to use: Cleaning build artifacts, removing temporary files, preparing clean workspace.

πŸ“– Official Documentation

Git Aliases* (Element: Al)

Aliases are created using git config, not a standalone command

Create shortcuts for frequently used Git commands.

git config --global alias.co checkout          # Create "git co" shortcut
git config --global alias.br branch            # Create "git br" shortcut
git config --global alias.ci commit            # Create "git ci" shortcut
git config --global alias.st status            # Create "git st" shortcut
git config --global alias.unstage "reset HEAD --"  # Create "git unstage"
git config --global alias.last "log -1 HEAD"   # Create "git last" shortcut
git config --global alias.visual "!gitk"       # External command alias
git config --global alias.graph "log --oneline --graph --decorate --all"

When to use: Creating shortcuts for frequently used commands, simplifying complex Git operations, improving workflow efficiency.

πŸ“– Official Documentation


🎯 Special Commands & Aliases

Advanced Git Techniques

Complex merge log analysis:

# Show merge commits between branches
git log origin/main..HEAD --merges --oneline

# Show commits that changed specific file
git log -p --follow -- filename.txt

# Find commits that added or removed specific text
git log -S "function_name" --oneline

Branch management shortcuts:

# Delete all merged branches except main
git branch --merged | grep -v "\*\|main\|develop" | xargs -n 1 git branch -d

# Push new branch and set upstream in one command
git push -u origin feature/new-feature

# Rename and push branch in one operation (delete old, push new)
git push origin :old_name new_name    # Deletes old_name, pushes new_name

Git Extensions & Custom Commands

Git contrib - Community contributed scripts (varies by installation):

# These may be available depending on your Git installation:
git summary                    # Show repository statistics
git effort                     # Show file effort/churn metrics
git authors                    # List authors and contribution stats

# Check what contrib scripts you have:
ls $(git --exec-path)/git-*    # List all git commands

Git jump - Quick navigation (requires custom setup):

# Example custom git jump alias for quick branch switching:
git config alias.jump '!f() { git checkout $(git branch | grep "$1" | head -1 | sed "s/^..//"); }; f'

# Usage after setup:
git jump feature    # Jumps to first branch matching "feature"

More Useful Git Commands

Repository analysis:

git shortlog -sn               # Contributor statistics
git rev-list --count HEAD      # Total number of commits
git ls-files | wc -l          # Count tracked files
git for-each-ref --sort=-committerdate refs/heads/  # Recently active branches

Advanced file operations:

git show HEAD:path/to/file     # Show file content from specific commit
git restore --source=HEAD~1 file.txt  # Restore file from previous commit
git ls-tree -r HEAD            # List all files in repository

Debugging and analysis:

git reflog                     # Show reference log (recover "lost" commits)
git cherry-pick commit-hash    # Apply specific commit to current branch
git stash                      # Temporarily save uncommitted changes
git clean -fd                  # Remove untracked files and directories

Useful Git aliases to add to your ~/.gitconfig:

[alias]
    co = checkout
    br = branch
    ci = commit
    st = status
    unstage = reset HEAD --
    last = log -1 HEAD
    visual = !gitk
    pushf = push --force-with-lease
    sync = !git fetch --all && git rebase origin/main

πŸ”¬ The Periodic Properties

Just like elements in the periodic table have patterns and properties, Git commands also have characteristics:

  • Atomic Operations: Commands that complete entirely or not at all
  • State Changing: Commands that modify repository state vs. read-only operations
  • Local vs Remote: Commands that work locally vs. those that communicate with remotes
  • Safe vs Destructive: Commands that can lose data vs. those that cannot

🎯 Quick Reference Card

Element Group Primary Use Key Commands
Basic Daily workflow init, add, commit, status, config, stash, rm, mv, alias*
Navigation Moving around checkout, branch, switch, tag, reflog
Remote Collaboration remote, push, pull, fetch, clone
History Understanding log, diff, show, blame, rev-list
Debugging Problem solving bisect, rerere
Advanced Power features submodule, reset, rebase, squash, worktree, revert
Collaboration Working together send-email, request-pull
Maintenance Repository health gc, fsck, fast-export, fast-import, prune, clean

License

This project is licensed under the terms of the MIT open source license. Please refer to the LICENSE file for the full terms.


πŸ“– Additional Resources


Made with ❀️ by Copilot and mbianchidev for Git Merge 2025 "git commit --amend -m 'Oops, fixed my message!' -m 'p.s. I see you reaching for VSCode's UI instead of the good ol' command line for git'"

About

Git merge 2025 talk repo for the periodic table of git by @mbianchidev

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •