mirror of
https://github.com/BreizhHardware/git-katas.git
synced 2026-05-09 00:06:43 +02:00
A set of exercises for deliberate Git Practice
- Shell 53.7%
- PowerShell 42.2%
- Python 4.1%
| .github/workflows | ||
| 3-way-merge | ||
| advanced-rebase-interactive | ||
| alias | ||
| amend | ||
| bad-commit | ||
| basic-branching | ||
| basic-cherry-pick | ||
| basic-cleaning | ||
| basic-commits | ||
| basic-revert | ||
| basic-staging | ||
| basic-stashing | ||
| bisect | ||
| change-author | ||
| commit-on-wrong-branch | ||
| commit-on-wrong-branch-2 | ||
| configure-git | ||
| detached-head | ||
| diff-advance | ||
| docs | ||
| ff-merge | ||
| git-attributes | ||
| git-tag | ||
| ignore | ||
| images | ||
| investigation | ||
| lfs | ||
| master-based-workflow | ||
| merge-conflict | ||
| merge-driver | ||
| merge-mergesort | ||
| objects | ||
| pre-push | ||
| rebase-branch | ||
| rebase-exec | ||
| rebase-interactive-autosquash | ||
| rebase-multiple-commits | ||
| reorder-the-history | ||
| reset | ||
| restore | ||
| reverted-merge | ||
| save-my-commit | ||
| signed-commits | ||
| squashing | ||
| submodules | ||
| subtree | ||
| utils | ||
| .coderabbit.yaml | ||
| .editorconfig | ||
| .gitattributes | ||
| .gitignore | ||
| LICENSE.txt | ||
| Overview.md | ||
| README.md | ||
| SHELL-BASICS.md | ||
| test-all.sh | ||
| test.ps1 | ||
| test.sh | ||
| testzsh.sh | ||
Git Katas
Start
- Clone this repository
- Go into the folder you want to solve an exercise in
- Run the
setup.shscript - Consult the README.md in that folder to get a description of the exercise
Basic Git Katas
- basic-commits - Very basic creation of commits.
- basic-staging - Interacting with the stage (index).
- basic-branching - The first stride into branching.
- ff-merge - A tour around the most trivial of merges.
- 3-way-merge - A basic merge, involving multiple diverged branches.
- merge-conflict - A basic merge between diverging branches with incompatible (but simple) changesets.
- merge-mergesort - A merge conflict with actual code.
- rebase-branch - Using rebase as an alternative to merging.
- basic-revert - Use revert to revert a change
- 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.
- basic-cleaning - Cleaning the workspace.
- amend - Amending previous commits.
- reorder-the-history - We might have created our commits in a suboptimal order, practice to fix that scenario here.
- 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
- advanced-rebase-interactive - Practice using the interactive rebase commands.
- basic-stashing - The first stride into stashing.
- ignore - The basics of using the
.gitignorefile. And usinggit rm. - submodules - Submodules are loathed by many. Run through this exercise to see what the ruckus is all about.
- 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
- 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.
- commit-on-wrong-branch-2 - Another exercise on what to do if you have accidentally committed on the wrong branch.
- save-my-commit - Should you accidentally or on purpose delete a commit, go here to try and save it. You will use the reflog.
- detached-head - git complains that you are in a "You are in 'detached HEAD' state". What do you do?
- change-author - Change the author of commits
Katas On Advanced features
- 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.
- bad-commit - Using
git bisectto find a bad commit. - bisect - Another kata using
git bisect. - pre-push - A quick exercise in using Git hooks.
- Investigation - Discover what is going on in a Git repo, figure out what it looks like under the hood.
- 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"
