Skip to Content
DevopsGitGit WorkflowBasics

Git Basics

Example: File Status Workflow

The following example shows how a file moves through different Git states.

1. Initialize a Repository

git init

Output:

Initialized empty Git repository in /path/to/project/.git/

2. Create a File

touch example.txt

Check the repository status:

git status

Output:

On branch main No commits yet Untracked files: example.txt

The file is currently untracked.


3. Add the File to the Staging Area

git add example.txt

Check the status again:

git status

Output:

Changes to be committed: new file: example.txt

The 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.txt

Check the status:

git status

Output:

nothing to commit, working tree clean

The repository is now clean.


5. Modify the File

Edit the file:

vim example.txt

Check the status again:

git status

Output:

Changes not staged for commit: modified: example.txt

The file is now modified but not staged.

Last updated on