Git Basics
Example: File Status Workflow
The following example shows how a file moves through different Git states.
1. Initialize a Repository
git initOutput:
Initialized empty Git repository in /path/to/project/.git/2. Create a File
touch example.txtCheck the repository status:
git statusOutput:
On branch main
No commits yet
Untracked files:
example.txtThe file is currently untracked.
3. Add the File to the Staging Area
git add example.txtCheck the status again:
git statusOutput:
Changes to be committed:
new file: example.txtThe file is now staged.
4. Create the First Commit
git commit -m "My first commit"Example output:
[main (root-commit) 1234567] My first commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 example.txtCheck the status:
git statusOutput:
nothing to commit, working tree cleanThe repository is now clean.
5. Modify the File
Edit the file:
vim example.txtCheck the status again:
git statusOutput:
Changes not staged for commit:
modified: example.txtThe file is now modified but not staged.
Last updated on