We'll work a bit with the .gitignore
file in this kata.
In this file you can specify both file extensions and folder structures that you do not want Git to track.
You can still git add
files and folder that are ignored in the .gitignore
file.
We will also work with git rm
, which is the Git remove command. git rm
does just the same as removing a file from your working directory, and then staging that change by issuing a git add filename
on the file that was just deleted.
Sometimes you add a file by accident that was not meant for Git e.g. binary files, class files etc.
If you want to signal to Git that a file needs to be removed from git, but still want it in your working directory, then use git rm --cached
to issue a remove command on the staging area, but not in your working directory.
- Run
source setup.sh
(or.\setup.ps1
in PowerShell)
- Create a file with the name
foo.s
- What is the output of
git status
? - Create a
.gitignore
file in your working directory containing*.s
- What is the output of
git status
? - Commit the
.gitignore
file - Commit
file1.txt
- Add
txt
files to.gitignore
by adding a line in the file containing*.txt
- What does
git status
tell us? - Change
file1.txt
- What does
git status
tell us? Why was the file tracked even though thetxt
extension is in the ignore file? - Make another text file
file2.txt
in the repository, what doesgit status
look like now? Why is it not tracked? - Stage the removal of
file1.txt
with the commandgit rm --cached
- What does
git status
say? - Create a new file called
file3.txt
and add the line!file3.txt
to.gitignore
. (See note below) - What does
git status
say? Can you think of a use-case for keeping track of a file although the extension is ignored?
If you are using zsh
instead of bash
(default on Mac and some Linux') then echo "!file3.txt" >> .gitignore
will fail because of shell expansion. Either use an editor to modify the file or escape the !
e.g. echo "\!file3.txt" >> .gitignore
git rm
git add
git commit
git commit -m
git rm --cached
You can set up aliases as such:
git config --global alias.lol 'log --oneline --graph --all'
This might be useful to you.