During my practical sessions at Luxdev HQ, I started working with Git and GitHub as part of my development workflow. At first, some of the commands seemed to do almost the same thing, especially git add, git commit, and git push. With practice, I started understanding that each command represents a different stage of the workflow
In this article, I will explain each stage using a simple Python project and some of the commands I have been practicing.
1. Starting With a Simple Project
For this example, imagine that I am working on a small Python calculator project.
My project folder might look like this:
mycalculator/
- calculator.py
- README.md
Inside calculator.py, I could start with something very simple
print("Welcome to my calculator")
At this point, I am just working normally on my computer. I can open the file in VS Code, change the code, save it, and continue working.
This is where the working directory comes in
2. Understanding the Working Directory
`The working directory is basically the project folder where I am doing my actual work.
If I create a new file, edit an existing file, or delete a file, those changes happen in my working directory.
print("Welcome to my Python calculator")
I have changed the file, but I have not yet told Git that I want to record this change.
This is where I found git status very useful.
I started thinking of git status as my what is going on? command.
Whenever I am not sure what Git knows about my project, I can run git status and see which files have been changed, which files are untracked, and which changes are staged.
3. Understanding Untracked and Modified Files
One thing a beginner can easily find confusing is the difference between an untracked file and a modified file.
Suppose I create a new file called:
hello.py
Git may show it as an untracked file
On the other hand, if Git already knows about calculator.py and I change something inside it, Git can tell me that the file has been modified.
So I can think about it like this:
Untracked
→ Git has not started tracking this file.
Modified
→ Git already knows the file, but I have changed it.
4. The Staging Area
This was one of the parts I had to think about the most when learning Git.
At first, I wondered:
If I have already changed my file, why do I need to add it?
I eventually understood that Git gives me a staging area where I can select the changes that I want to include in my next commit.
For example:
git add calculator.py
This tells Git that I want the changes in calculator.py to be included in my next commit.
The important thing I learned is that git add does not upload the file to GitHub.
11. The Difference Between Commit and Push
It simply moves the change from my working directory into the staging area.
5. Creating a Commit
Once I am satisfied with the changes I have staged, I can create a commit.
git commit -m "Update calculator message"
Top comments (1)
great