Skip to content

Fr4nkFletcher/learn-git-the-super-hard-way

 
 

Repository files navigation

learn-git-the-super-hard-way

Translated from Mandarin here

GitBook

Table of Contents

  1. Create Working Environment (git init)
  2. Directly Manipulate Objects (git commit)
  3. Directly Manipulate References (git branch)
  4. Directly Manipulate the Index (git add / restore)
  5. Directly Manipulate HEAD (git switch)
  6. Directly Manipulate Remotes (git pull / push)
  7. Directly Manipulate Merges (git diff / merge)
  8. Directly Manipulate Commits (git rebase)
  9. Search and View History (git log / blame / grep)
  10. The Evil Submodule (git submodule)
  11. Batch Processing and Automation
  12. Configuration and Aliases (git config)
  13. Single Repo Multi-Branch Workflow
  14. GPG Signatures
  15. Data Import and Export (git archive)
  16. Data Recovery and Emergency

This tutorial also provides a cheatsheet for review and self-testing.

If you are not familiar with any of the commands in the cheatsheet, you may want to start with some basic tutorials: Beginner, Intermediate, Advanced. The advanced tutorial can be studied alongside this one.

If you have already mastered all the commands in the cheatsheet, this tutorial may be too basic for you. Consider moving on to the Git Reference or Git source code.

After completing this tutorial, you should have mastered 1% of all Git usage.

Note: Detailed explanations of git reset/git checkout are in Chapter 4. It is highly recommended to use the more powerful and intuitive git restore and git switch.

Basic Conventions

To better understand Git at its core, this tutorial introduces multiple ways to perform the same operation. The table below describes which method is best suited for different scenarios.

Level Meaning Usage Scenario
Lv0 Pure manual implementation, no Git CLI Learning Git internals
Lv1 Use low-level Git CLI with manual steps For extremely special Git operations
Lv2 Use low-level Git CLI For unconventional Git operations
Lv3 Use standard Git CLI Daily use
Lv4 Git Alias Extending Git for daily use
Lv5 Scripting with Git CLI For unconventional extensions, occasional use

Git Command Line Basics

Global Command Line Parameters

  • cwd defaults to ., meaning to cd there before running subsequent commands
  • work-tree defaults to GIT_WORK_TREE or ., but not all commands involve the worktree
  • git-dir defaults to GIT_DIR or ./.git:
    • If ./.git is a directory, it is used as the repo
    • If ./.git is a file, its content (usually an absolute path) is used as the repo
git [-C <cwd>] [--git-dir=<repo>] [--work-tree=<worktree>] <command> [args]

Specific Git Command Parameters

Most commands follow this format for arguments:

  • object: an object expression
    • Usually composed of references, object SHA1, ^, ~, :, etc.
    • See git rev-parse (Lv2) for the full list
  • path: a file path
  • -- can be omitted if there is no ambiguity

Note: The presence or absence of the <path> parameter can fundamentally change the command's meaning

git <command> [options] [<object>]
git <command> [options] [<object>] -- [<path>]

Git Command List

This tutorial covers all common Git commands and more than half of the uncommon ones. See the Roadmap.

License

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

About

An unconventional Git tutorial (translated from Mandarin)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published