A set of exercises for deliberate Git Practice
  • Shell 53.7%
  • PowerShell 42.2%
  • Python 4.1%
Find a file
2026-01-14 09:33:35 +01:00
.github/workflows Allow the use of older node 2024-09-06 11:57:06 +02:00
3-way-merge Fix typo in 3-way-merge README.md 2024-09-06 12:44:59 +02:00
advanced-rebase-interactive Add fake remote to advanced-rebase-interactive 2021-01-19 14:19:32 +01:00
alias Fixing a typo in alias/README.md 2022-07-25 15:31:42 +02:00
amend Add an explanation for commands to run with amend. 2020-09-11 14:47:49 +02:00
bad-commit Fix the start version in bad-commit 2025-12-23 12:22:52 +01:00
basic-branching Update to use git switch instead of git checkout 2021-10-29 22:23:21 +02:00
basic-cherry-pick UPDATE cherry-pick, remove --decorate flag 2022-10-24 22:34:22 +02:00
basic-cleaning Consistently use dashes in utils function names 2020-05-25 12:41:58 +02:00
basic-commits Fix missing quote for initial git config 2026-01-14 09:33:35 +01:00
basic-revert UPDATE basic-revert, remove --decorate flag 2022-10-24 22:34:22 +02:00
basic-staging Update README.md 2021-11-05 11:39:07 +01:00
basic-stashing Merge pull request #235 from praqma-training/git-katas-issue-59 2020-04-15 12:28:48 +02:00
bisect Use pre-setup & post-setup as suggested in review 2024-11-04 14:38:34 +01:00
change-author Fix PR review findings 2020-09-11 09:55:49 +02:00
commit-on-wrong-branch Update to use git switch instead of git checkout 2021-10-29 22:23:21 +02:00
commit-on-wrong-branch-2 Consistently use dashes in utils function names 2020-05-25 12:41:58 +02:00
configure-git Add kata on aliases 2020-11-06 10:54:13 +01:00
detached-head Update to use git switch instead of git checkout 2021-10-29 22:23:21 +02:00
diff-advance Small fix to example command 2024-11-02 10:29:40 +01:00
docs Celebrate 1000 Stars 2023-09-11 17:35:31 +02:00
ff-merge Improve wording in ff-merge README to be more correct 2022-10-25 14:12:18 +02:00
git-attributes Update README.md 2022-10-27 23:24:50 +02:00
git-tag Add feature to test all kata setup.sh scripts 2021-03-26 11:32:14 +01:00
ignore Improve "ignore" kata 2023-08-14 21:56:04 +02:00
images Add clone step to README Gif 2019-10-21 13:50:06 +02:00
investigation Consistently use dashes in utils function names 2020-05-25 12:41:58 +02:00
lfs Fine tune linting of LFS readme 2022-10-25 22:08:12 +02:00
master-based-workflow UPDATE master-based-workflow, remove --decorate flag 2022-10-24 22:34:22 +02:00
merge-conflict Fix language in README.md in merge-conflict kata 2022-05-19 15:43:19 +02:00
merge-driver Update README.md for bisect and merge-driver 2020-07-01 09:07:09 +02:00
merge-mergesort Avoid confirmation prompt in mergesort setup script 2021-11-25 10:36:40 +01:00
objects Fixed numbering, so that it now increments both in shell and in markdown 2019-08-07 14:44:06 +02:00
pre-push Add setup.ps1 for pre-push kata 2020-07-01 09:07:09 +02:00
rebase-branch Replace checkout with switch 2022-08-28 08:19:18 +02:00
rebase-exec Add setup.ps1 and verify.ps1 for rebase-exec kata 2020-07-01 09:07:09 +02:00
rebase-interactive-autosquash Consistently use dashes in utils function names 2020-05-25 12:41:58 +02:00
rebase-multiple-commits Add rebase-multiple-commits exercise 2023-09-04 21:41:45 +02:00
reorder-the-history Consistently use dashes in utils function names 2020-05-25 12:41:58 +02:00
reset Consistently use dashes in utils function names 2020-05-25 12:41:58 +02:00
restore Fix restore kata title 2020-10-30 13:39:00 +01:00
reverted-merge Update to use git switch instead of git checkout 2021-10-29 22:23:21 +02:00
save-my-commit Add missing shebang to save-my-commit/setup.sh 2022-05-19 15:41:22 +02:00
signed-commits created initial GPG signing kata 2024-01-24 18:37:19 +01:00
squashing Consistently use dashes in utils function names 2020-05-25 12:41:58 +02:00
submodules More improvements to submodules README 2022-10-25 22:20:34 +02:00
subtree Remove remaining --decorate flags in subtree kata 2022-10-24 22:34:22 +02:00
utils Add Git LFS exercise 2022-08-24 09:19:02 +02:00
.coderabbit.yaml Add config file for CodeRabbit code review tool 2024-04-26 11:56:28 +02:00
.editorconfig Add .editorconfig to keep content more clean 2022-08-19 00:32:35 +02:00
.gitattributes Added .gitattributes to make line endings consistent. 2019-09-20 14:21:49 +02:00
.gitignore Celebrate 1000 Stars 2023-09-11 17:35:31 +02:00
LICENSE.txt Add license 2017-02-10 08:27:23 +01:00
Overview.md Move reverted-merge to advanced 2025-12-23 13:19:17 +01:00
README.md Fixup 2026-01-04 01:04:30 +01:00
SHELL-BASICS.md Mention less in SHELL-BASICS.md 2019-11-27 09:52:15 +01:00
test-all.sh Test on both bash and zsh 2021-03-26 14:09:47 +01:00
test.ps1 Create GitHub actions CI pipeline for running test scripts (#265) 2020-07-01 09:06:20 +02:00
test.sh Make the test.sh script actually fail! 2021-03-26 11:32:14 +01:00
testzsh.sh Complete zsh test 2020-09-04 10:05:18 +02:00

Git Katas

Start

Quick Start

  • Clone this repository
  • Go into the folder you want to solve an exercise in
  • Run the setup.sh script
  • Consult the README.md in that folder to get a description of the exercise

Basic Git Katas

  1. basic-commits - Very basic creation of commits.
  2. basic-staging - Interacting with the stage (index).
  3. basic-branching - The first stride into branching.
  4. ff-merge - A tour around the most trivial of merges.
  5. 3-way-merge - A basic merge, involving multiple diverged branches.
  6. merge-conflict - A basic merge between diverging branches with incompatible (but simple) changesets.
  7. merge-mergesort - A merge conflict with actual code.
  8. rebase-branch - Using rebase as an alternative to merging.
  9. basic-revert - Use revert to revert a change
  10. reset - Reset is a powerful and slightly dangerous command if you do not know what you are doing. Go through the three modes of resetting here.
  11. basic-cleaning - Cleaning the workspace.
  12. amend - Amending previous commits.
  13. reorder-the-history - We might have created our commits in a suboptimal order, practice to fix that scenario here.
  14. squashing - A lot of small commits is good when you are working locally, but for sharing your code, it might be more beneficial to deliver your code changes in large sets. Go here to experiment with that. Write a good commit
  15. advanced-rebase-interactive - Practice using the interactive rebase commands.
  16. basic-stashing - The first stride into stashing.
  17. ignore - The basics of using the .gitignore file. And using git rm.
  18. submodules - Submodules are loathed by many. Run through this exercise to see what the ruckus is all about.
  19. git-tag - Tags are convenient for keeping track of commits that bump a version number. In this exercise, you will list, add and delete tags.

Katas that solve standard problems

  1. commit-on-wrong-branch - If we accidentally put unpushed commits on the wrong branch, how do we effectively move them to another branch before our work on that branch.
  2. commit-on-wrong-branch-2 - Another exercise on what to do if you have accidentally committed on the wrong branch.
  3. save-my-commit - Should you accidentally or on purpose delete a commit, go here to try and save it. You will use the reflog.
  4. detached-head - git complains that you are in a "You are in 'detached HEAD' state". What do you do?
  5. change-author - Change the author of commits

Katas On Advanced features

  1. reverted-merge - We revert a merge, but, after fixes are added to the merged branch, we want the changes from merge and the new fixes.
  2. bad-commit - Using git bisect to find a bad commit.
  3. bisect - Another kata using git bisect.
  4. pre-push - A quick exercise in using Git hooks.
  5. Investigation - Discover what is going on in a Git repo, figure out what it looks like under the hood.
  6. rebase-exec - Run tests on every commit using git rebase --exec

Cheatsheet

A collection of useful commands to use throughout the exercises:

# Initializing an empty git repository.
git init            # Initialize an empty git repository under current directory.

# Cloning a repository
git clone https://github.com/praqma-training/git-katas.git      # Clone this repository to your current working directory

# Git (user and repo level) configurations
git config --local user.name "Repo-level Username"          # For setting a local git repo level user name.
git config --local user.email "Repo-level.Email@Example.com" # For setting a local git repo level user email.
                                                            # --global -> User level git config stored in <user-home>/.gitconfig for e.g. ~/.gitconfig
                                                            # --local -> repo level config stored in repo's main dir under .git/config


# See local changes
git status                  # Show the working tree status
git diff                    # Show changes current working directory (not yet staged)
git diff --cached           # Show changes currently staged for commit

# Add files to staging (before a commit)
git add myfile.txt          # Add myfile.txt to stage
git add .                   # Add entire working directory to stage

# Make a commit
git commit                              # Make a new commit with the changes in your staging area. This will open an editor for a commit message.
git commit -m "I love documentation"    # Make a new commit with a commit message from the command line
git commit -a                           # Make a new commit and automatically "add" changes from all known files
git commit -am "I still do!"            # A combination of the above
git commit --amend                      # Re-do the commit message of the previous commit (don't do this after pushing!)
                                        #   We _never_ change "public history"
git reset <file>                        # Unstage a staged file leaving in working directory without losing any changes.
git reset --soft [commit_hash]          # resets the current branch to <commit>. Does not touch the staging area or the working tree at all.
                                        # --hard mode would discard all changes.

# Configuring a different editor
## Avoid Vim but stay in terminal:
- `git config --global core.editor nano`

## For Windows:
- Use Notepad:
`git config --global core.editor notepad`

- or for instance Notepad++:
`git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"`


# See history
git log             # Show commit logs
git log --oneline   # Formats commits to a single line (shorthand for --pretty=oneline  --abbrev-commit )
git log --graph     # Show a graph commits and branches
git log --pretty=fuller     # To see commit log details with author and committer details, if any different.
git log --follow <file>     # List the history of a file beyond renames
git log branch2..branch1    # Show commits reachable from branch1 but not from branch2

# Deferring
git stash                               # Stash (store temporarily) changes in working branch and enable checkingout a new branch
git stash list                          # List stored stashes.
git stash apply <stash>                 # Apply given <stash>, or if none given the latest from stash list.


# Working with Branches
git branch my-branch       # Create a new branch called my-branch
git switch my-branch     # Switch to a different branch to work on it
git switch -c my-branch  # Create a new branch called my-branch AND switch to it
git branch -d my-branch    # Delete branch my-branch that has been merged with master
git branch -D my-branch    # Forcefully delete a branch my-branch that hasn't been merged to master

# Merging
git merge master         # Merge the master branch into your currently checked out branch.
git rebase master        # Rebase current branch on top of master branch

# Working with Remotes
git remote              # Show your current remotes
git remote -v           # Show your current remotes and their URLs
git push                # Publish your commits to the upstream master of your currently checked out branch
git push -u origin my-branch  # Push newly created branch to remote repo setting up to track remote branch from origin.
                              # No need to specify remote branch name, for e.g., when doing a 'git pull' on that branch.
git pull                # Pull changes from the remote to your currently checked out branch

# Re/moving files under version control
git rm <path/to/the/file>                 # remove file and stage the change to be committed.
git mv <source/file> <destination/file>   # move/rename file and stage the change to be committed.

# Aliases - it's possible to make aliases of frequently used commands
#   This is often done to make a command shorter, or to add default flags

# Adding a shorthand "sw" for "switch"
git config --global alias.sw "switch"
# Usage:
git sw master     # Does a "git switch master"

## Logging
git log --graph --oneline --all # Show a nice graph of the previous commits
## Adding an alias called "lol" (log oneline..) that shows the above
git config --global alias.lol "log --graph --oneline --all"
## Using the alias
git lol     # Does a "git log --graph --oneline --all"