Git Tutorial
Track changes, branch safely and collaborate with version control.
Getting started5 lessons
- 1Git IntroductionVersion control in plain words.
- 2Setup and git initConfigure your name and create a repo.
- 3Git ConfigSettings live at three levels: system, global (your user) and local (one repo).
- 4Version and Helpgit --version shows the installed version and git help <command> opens the manual for any .
- 5Inside the .git FolderGit stores everything in the hidden .git folder: HEAD points at the current branch, object.
Basics39 lessons
- 6Staging and CommittingThe core workflow.
- 7Status and LogSee what changed and what happened.
- 8DiffCompare changes.
- 9.gitignoreKeep files out of Git.
- 10Undoing Changesrestore, reset and amend.
- 11Writing Commit MessagesA good message has a short summary in the imperative mood, such as Add login form.
- 12Staging Selected Filesgit add takes a path, so you can stage only some of your changes.
- 13Removing and Renaming Filesgit rm deletes a file and stages the deletion.
- 14Listing and Showing Filesgit ls-files lists tracked files.
- 15Commit Tracked Changes in One Stepgit commit -a stages all modified tracked files before committing.
- 16What Is Version ControlVersion control records every change to your files so you can go back, compare and work to.
- 17Working Tree, Index and RepositoryFiles move through three areas: the working tree where you edit, the index (staging area) .
- 18Your First Commitgit add stages files and git commit saves a snapshot with a message.
- 19Reading git statusgit status shows staged, unstaged and untracked files.
- 20Viewing Changes with diffgit diff shows unstaged changes.
- 21Reading the Loggit log lists commits.
- 22The .gitignore FileList patterns of files Git should not track, such as build output and secrets.
- 23Amending the Last Commitgit commit --amend changes the last commit message or adds forgotten files.
- 24Discarding Changesgit restore file throws away working changes and git restore --staged unstages.
- 25Looking Inside a Commitgit show prints a commit and its changes.
- 26Lightweight TagsTags name a commit, such as a release.
- 27Renaming and Movinggit mv renames and stages.
- 28Staging Parts with add -pgit add -p stages selected hunks.
- 29Empty Commits and Messages--allow-empty makes a commit with no changes, handy to trigger CI.
- 30AliasesAliases shorten long commands.
- 31Configuring Gituser.name, user.email, core.editor and init.defaultBranch are common settings.
- 32Getting Helpgit help command opens the manual and command -h prints a short usage.
- 33Looking at Old Versionsgit show and git restore let you view or take old versions without moving branches.
- 34Finding Changes with log -Sgit log -S finds commits that added or removed a piece of text.
- 35Comparing Branchesgit diff a..b and git diff --stat compare branches.
- 36Cherry Pickgit cherry-pick copies one commit onto the current branch.
- 37Squash Mergemerge --squash combines a branch into one staged change you commit yourself.
- 38Rebase Basicsrebase replays your commits on top of another branch for a straight history.
- 39Graph View--graph draws the branch shape and --all includes every branch.
- 40Bare RepositoriesA bare repository has no working tree and is what servers hold.
- 41A Daily Solo WorkflowPull, branch, commit often, merge, push.
- 42Practice: Make a ReleaseCommit, tag and list.
- 43Practice: Undo a MistakeRevert a bad commit and verify.
- 44Practice: Feature and MergeBranch, work, merge, clean up.
Inspecting history6 lessons
- 45Log Formatsgit log has many formats: --oneline, --format with placeholders like %an (author) and %s (.
- 46Filtering the LogFilter by author, message text, date or path.
- 47Inspecting a Commitgit show prints one commit and its diff.
- 48Blame: Who Changed This Linegit blame shows who last changed each line.
- 49Diff Variantsgit diff compares working tree and index.
- 50Shortlog and git grepgit shortlog -sn counts commits per author.
Undoing changes13 lessons
- 51Restore and Unstagegit restore file discards working changes.
- 52Reset: Soft, Mixed and Hard--soft moves the branch only.
- 53Revert: Undo Safelygit revert creates a new commit that reverses an earlier one.
- 54Clean Untracked Filesgit clean removes untracked files.
- 55Stash In Depthgit stash saves dirty work and cleans the tree.
- 56reset --soft and --mixed--soft moves the branch and keeps changes staged.
- 57reset --hard--hard moves the branch and resets files.
- 58Revert a Commitgit revert makes a new commit that undoes an old one without rewriting history.
- 59Cleaning Untracked Filesgit clean -n shows what would be deleted and -f deletes.
- 60Stashing Workgit stash saves unfinished changes and cleans the tree.
- 61Stash List and NamesName stashes with push -m and list them.
- 62The Reflog Safety NetThe reflog lists where HEAD has been, so you can recover from resets.
- 63Fix a Forgotten FileStage the forgotten file and amend the last commit.
Branches21 lessons
- 64BranchesWork in parallel.
- 65MergingCombine branches.
- 66Merge ConflictsFix clashing changes.
- 67Tags and StashMark releases and park work.
- 68Managing BranchesList with git branch, create with git branch name, rename with -m and delete merged branch.
- 69Switch Branchesgit switch changes branches and git switch -c creates and switches.
- 70Fast-forward and Merge CommitsIf main has not moved, a merge just fast-forwards.
- 71Aborting a MergeIf a merge goes wrong, git merge --abort returns to the state before it started.
- 72Annotated Tags and DescribeAnnotated tags store a message and tagger.
- 73Worktrees: Several Branches at Oncegit worktree add checks out another branch into a new folder that shares the same reposito.
- 74Creating BranchesA branch is a movable pointer to a commit.
- 75Switching Branchesgit switch moves between branches and updates your files.
- 76Renaming and Deleting Branchesgit branch -m renames and -d deletes a merged branch.
- 77Fast Forward MergeWhen main has not moved, merging a branch just moves the pointer forward.
- 78Merge CommitsIf both branches moved, Git makes a merge commit with two parents.
- 79Resolving a ConflictA conflict happens when both branches change the same lines.
- 80Aborting a Mergegit merge --abort returns to the state before the merge.
- 81Listing and Comparing Branchesgit branch -v shows last commits, --merged lists merged branches and git log a..b shows co.
- 82Branch NamingUse short lowercase names with a prefix such as feature/login or fix/typo.
- 83Detached HEADChecking out a commit instead of a branch gives a detached HEAD.
- 84Getting a File from Another Commitgit restore --source takes a file from any commit.
Remote and teamwork15 lessons
- 85Remotes: clone, push and pullShare your work.
- 86GitHub FlowBranches and pull requests.
- 87Working With a RemoteA remote is another copy of the repository.
- 88Fetch versus Pullgit fetch downloads new commits without touching your branch.
- 89SubmodulesA submodule pins another repository at a commit inside yours.
- 90Pull Requests and ForksA fork is your own copy of someone else repository on the host.
- 91Cloninggit clone copies a repository and sets origin.
- 92Adding a RemoteA remote is a named URL.
- 93Upstream and TrackingA tracking branch knows its remote counterpart so status can show ahead and behind.
- 94Remote BranchesRemote tracking branches look like origin/main.
- 95Deleting Remote BranchesPush with --delete removes a branch on the remote.
- 96Pull Request FlowCreate a branch, commit, push it and open a pull request on the hosting site.
- 97Pushing TagsTags are not pushed by default.
- 98Push and Pullpush sends commits to the remote and pull fetches and merges new ones.
- 99fetch Without Merginggit fetch downloads new work but does not change your branch.
Advanced GitPremium14 lessons
- 100RebaseA straighter history.
- 101Cherry-pick and ResetMove and rewind commits.
- 102Reflog and BisectRecover and hunt bugs.
- 103Hooks, Aliases and Good HabitsAutomate and stay tidy.
- 104Squashing CommitsSquash several small commits into one clean commit with git reset --soft followed by a new.
- 105Fixup and Autosquashgit commit --fixup marks a commit to be folded into an earlier one.
- 106Rebase --ontogit rebase --onto moves a range of commits onto a new base.
- 107Reflog: Recover Lost CommitsThe reflog records every place HEAD has been.
- 108Bisect: Find the Bad Commitgit bisect binary searches history for the commit that broke something.
- 109Hooks: Block Bad CommitsHooks are scripts in .git/hooks.
- 110Aliases and Config TricksAliases shorten long commands.
- 111.gitattributes and Line Endings.gitattributes sets per path rules such as line endings and diff behaviour.
- 112Shallow and Partial Clones--depth 1 downloads only the latest commit, which speeds up big repositories and CI jobs.
- 113Notes and Archivegit notes attach extra text to a commit without changing it.
Git in practicePremium6 lessons
- 114Debugging .gitignoregit check-ignore -v tells which rule ignores a file.
- 115Detached HEADChecking out a commit directly leaves HEAD detached, which means no branch follows your ne.
- 116Branching StrategiesTrunk based development uses short lived branches merged into main often.
- 117Keeping Secrets Out of GitNever commit passwords or keys.
- 118Git with CI and Code ReviewCI runs tests on every push.
- 119Troubleshooting Common ProblemsCommon fixes: undo the last commit but keep work with reset --soft, change the last messag.