Problem
After you have a git repository set up, in order for git to be useful, you will want to save and load your code.
In git, saving code is called staging and committing your code. Loading code is called checking out your code. You can checkout specific branches, commits, or tags.
Solution
Staging and Committing
In git, saving your code is a 2-step process with git add
(or git stage
) and git commit
.
- Make the changes to the code
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
$ touch change1.txt
$ touch change2.txt
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
change1.txt
change2.txt
nothing added to commit but untracked files present (use "git add" to track)
git status
is a great way to get information from git on what the current state of your files are.
- Once you are ready to save/commit your changes, you’ll first stage the change.
$ git add change1.txt
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: change1.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
change2.txt