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.ps1in PowerShell)
- Create a file with the name
foo.s - What is the output of
git status? - Create a
.gitignorefile in your working directory containing*.s - What is the output of
git status? - Commit the
.gitignorefile - Commit
file1.txt - Add
txtfiles to.gitignoreby adding a line in the file containing*.txt - What does
git statustell us? - Change
file1.txt - What does
git statustell us? Why was the file tracked even though thetxtextension is in the ignore file? - Make another text file in the repository, what does
git statuslook like now? Why is it not tracked? - Stage the removal of
file1.txtwith the commandgit rm --cached - What does
git statussay? - Create a new file called
file2.txtand add the line!file2.txtto.gitignore. (See note below) - What does
git statussay? 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 "!file2.txt" >> .gitignore will fail because of shell expansion. Either use an editor to modify the file or escape the ! e.g. echo "\!file2.txt" >> .gitignore
git rmgit addgit commitgit commit -mgit rm --cached
You can set up aliases as such:
git config --global alias.lol 'log --oneline --graph --all'
This might be useful to you.