Skip to content

Commit

Permalink
Add kata on aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
P-A Lundblad authored and RandomSort committed Nov 6, 2020
1 parent bb52781 commit 6c8746e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
35 changes: 35 additions & 0 deletions alias/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Git kata: Aliases

While working, we tend to write a lot of commands. This can get tedious, especially when the commands are rather long. Git allows you to create an alias for commands, dramatically shortening the time spent typing them.

Aliases are stored in your git config and can thus be global or local. Global config is tied to your user, while local config lives inside a specific repository.

## Setup

1. Run `source setup.sh` (or `.\setup.ps1` in PowerShell)

## The task

1. View your config by running `git config --list`
2. Add a new global alias\
`git config --global alias.lol 'log --oneline --graph --all'`\
This allows you to call `git lol` as an alternative to `git log --oneline --graph --all`
3. Run your alias `git lol`
4. Run the full command `git log --oneline --graph --all`\
Are there any difference in the output?
5. Create another alias, this time local, that lists commits where you are the author\
`git config --local alias.lome "log --author=\"$(git config --get user.name)\""`
6. Run your alias `git lome`\
What does it show?
7. View your git config and its sources by running `git config --list --show-origin`\
Can you find your alias configurations?
8. Try running `git lome` in a different git repository\
Does it work?
9. Remove your `git lol` alias by running `git config --unset alias.lol`

## Useful commands

- `git config --list`
- `git config --list --show-origin`
- `git config get <configuration>`
- `git config --unset <configuration>`
9 changes: 9 additions & 0 deletions alias/setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
. ..\utils\make-exercise-repo.ps1

Set-Content -Value "dummy" -Path dummy.txt

git add dummy.txt
git commit -m "dummy commit"
Set-Content -Value "dummy2" -Path dummy.txt
git add dummy.txt
git commit -m "adding more content to dummy.txt"
15 changes: 15 additions & 0 deletions alias/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Include utils
source ../utils/utils.sh

kata="$(basename $(pwd))"
make-exercise-repo

echo "dummy" > dummy.txt
git add dummy.txt
git commit -m "dummy commit"
echo "dummy2" > dummy.txt
git add dummy.txt
git commit -m "adding more content to dummy.txt"

2 changes: 2 additions & 0 deletions configure-git/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ You can set up aliases as such:
This might be useful to you when you look at the Git graph.
Paste that into your terminal, and try it out with `git lol`.

More on aliases can be found in the alias kata.

### SSH authentication

- See https://help.github.com/articles/generating-an-ssh-key for details about authenticating against SSH-enabled repositories
Expand Down

0 comments on commit 6c8746e

Please sign in to comment.