There are multiple ways to solve this.
If you want to do the changes for the first commit without interferring with your current changes, you might want to use
git stash. This will put all your open changes away, allowing you to restore them later. Use
git status to see that they are not present anymore. Now create the first commit as you are used to. Next you can use
git stash pop to restore your original changes and create the second commit, doing your primary work.
Another way would be to do all required changes and then create two commits, both containing a part of your work. To do so you could use the index (also known as the staging area) provided by git. This is a special area you can use to prepare commits. Assuming you have changed multiple files, you can add each of them to the index using
git add. When doing
git commit only the files added to the index will be committed.
git status will show you which parts of your changes will be committed and which won't. For example it will look this way after changing files a.txt, b.txt and c.txt and afterwards doing
git add a.txt:
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
When you are doing
git commit in this state, only the changes to a.txt will be added to your commit.
Additional you can review the exact changes to be committed using
git diff --cached, which will show you a diff of all changes which are going to be committed.
If one file contains changes for both commits, you can also add only parts of it to the index by using "git add --patch b.txt". git will provide you an interactive mode which asks you for each change in the given file if it should be added to the index. This might get harder if you have changes in lines next to each other, which need to be splitted in the two commits, however there are ways to solve that too.
If you want to learn more about the staging area you might want to read this:
You also might want to read more about interactive adding here: