Challenge¶
- Run this code. It initializes a new git repo inside a directory named
yolo/
Don't forget to cd
to the parent directory where you want the yolo/
directory to reside, before running the
above code.
-
Insert a text file named
foo.txt
insideyolo/
-
Commit your changes with the message "first commit"
How do I create a text file from the command line?
Create an empty file using touch
Create a file with some text using echo
Solution¶
Explanation¶
Working Directory
The explanation below assumes that your working directory is the root of the repo. In other words, if you run
it should return
Otherwise, you need to
Status¶
Before we stage and commit the changes, let's review the state of our git repo using git status
.
git status
tells us that we have an untracked file - foo.txt
.
Untracked Files
Untracked files are files that have been created within your repo's working directory but have not yet been added to therepository's tracking index using git add
Stage¶
Before we can commit our changes, we need to stage them with git add
.
Let's run git status
again..
Now, instead of "Untracked files:"
we see "Changes to be committed:"
Commit¶
To commit our staged changes, we can use git commit
.
-m
is an alias for the--message
argument togit 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!