After you have finished making your changes, it is time to commit them.
-
Determine your file’s status. Remember that
git status
allows us to see the status of the files on our branch at any given time. Your file is listed under the headingUntracked files
.git status
-
Add your file to the staging area so it’s prepared to become part of the next commit.
git add <FILE-NAME>
-
See your file’s current status. Your file is now listed under the heading
Changes to be committed
. This tells us that the file is in the staging area. It also indicates this is a new file.git status
-
Commit your file. A commit tells Git to collect all of the files in the staging area and store them to version control as a single unit of work. Git will open your default text editor where you can enter the commit message.
git commit
-
Type the commit message, save and quit your editor.
- The default text editor associated with Git is vi in most cases, which requires that you press the
Esc
key then type:wq
to save and quit after entering your commit message. - Alternatively, you can bypass vi altogether and enter your commit message inline with
git commit -m "your message"
- The default text editor associated with Git is vi in most cases, which requires that you press the
-
See the history of commits:
git log
Tell me why
Understanding the GitHub Flow
Add and commit files on the command line.
-
Create a branch
-
Add commits
(This section deals with this step.)
- Open a Pull Request
- Collaborate, and make more commits
- Merge the Pull Request
The Two Stage Commit
After you have finished making your changes, it is time to commit them. When working from the command line, you will need to be familiar with the idea of the two stage commit.
When you work locally, your files exist in one of four states. They are either untracked, modified, staged, or committed.
An untracked file is one that is not currently part of the version controlled directory. These are typically new files.
Modified files are ones that Git already knows about, they have at least one other version in history.
To add these files to version control, you will create a collection of files that represent a discrete unit of work. We build this unit in the staging area.
When we are satisfied with the unit of work we have assembled, we will commit everything in the staging area.
In order to make a file part of the version controlled directory we will first do a git add
and then we will do a git commit
.