First Commit Solution¶
git add . git commit -m "first commit"
The explanation below assumes that your working directory is the root of the repo. In other words, if you run
it should return
bill@gates:~$ pwd /path/to/yolo
Otherwise, you need to
bill@gates:~$ cd /path/to/yolo
Before we stage and commit the changes, let's review the state of our git repo using
bill@gates:~$ git status On branch main No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) foo.txt nothing added to commit but untracked files present (use "git add" to track)
git status tells us that we have an untracked file -
- Untracked Files
Untracked files are files that have been created within your repo's working directory but have not yet been added to the repository's tracking index using
Before we can commit our changes, we need to stage them with
bill@gates:~$ git add foo.txt
bill@gates:~$ git add .
git status again..
bill@gates:~$ git status On branch main No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: foo.txt
Now, instead of "Untracked files:" we have "Changes to be committed:".
To commit our staged changes, we can use
bill@gates:~$ git commit -m "first commit" # (1)! [main (root-commit) 88d8887] first commit 1 file changed, 1 insertion(+) create mode 100644 foo.txt
-mis an alias for the
git commit. It should be a meaningful message regarding your changes in the commit.
What if I don't want to specify a message?
Shame! You should always provide a commit message!
Finally, let's check our commit history with
bill@gates:~$ git log commit 88d8887beaad2cfd37d04fb00f38c05077581057 (HEAD -> main) Author: bill123 <firstname.lastname@example.org> Date: Sun Sep 11 13:09:50 2022 -0500 first commit