At this point, we have learned git pull, branches, git add, git commit, and git push. In real development, these commands are rarely used in isolation. They usually form a repeatable workflow.
Suppose you are working on a GitHub project and need to build a new search feature. A common workflow starts from main.
First, switch to main:
git switch mainThen get the latest remote changes:
git pullThis makes sure you begin your work from the latest version of the project instead of an older local copy.
Create a Development Branch
After updating main, create a new branch:
git switch -c feature/searchYour work now happens on:
feature/searchinstead of directly on main.
You can confirm your current branch with:
git branchand may see:
* feature/search
mainEdit and Review Your Code
Now you can develop normally, perhaps changing files such as:
search.js
search.htmlOnce you have made some changes, review the diff in VS Code Source Control so you know exactly what changed.
Then run:
git statusto check the repository state.
If everything looks correct, stage the changes:
git add .and check again:
git statusto make sure the right files are ready for the next commit.
Create a Commit
Now create a commit:
git commit -m "Add search feature"A feature branch can contain more than one commit. You do not need to wait until the entire feature is finished before committing.
For example:
Add search input
Add search API request
Handle empty search results
Fix search loading stateSeveral focused commits are often easier to understand than one huge commit.
Push the Branch to GitHub
Once you have commits, upload the branch to GitHub.
The first time:
git push -u origin feature/searchFor later updates on the same branch:
git pushGitHub will now have a remote branch called:
feature/searchThe next step in a team project is usually not to merge directly into main. Instead, you open a Pull Request so the changes can be reviewed and checked.
Pull Requests are covered later with the collaboration material.
A Complete Everyday Workflow
Putting everything together:
1. Switch to main → 2. Pull the latest code → 3. Create a feature branch → 4. Edit code → 5. Review the diff → 6. git add → 7. git commit → 8. git push → 9. Open a Pull Request on GitHub
The commands might look like:
git switch main
git pull
git switch -c feature/searchAfter development:
git status
git add .
git commit -m "Add search feature"
git push -u origin feature/searchThis is already very close to the basic Git workflow used by many real teams.
KNOWLEDGE QUIZ
What If the Task Is Not Finished Yet?
You do not need to avoid commits just because the whole feature is incomplete.
For a larger payment feature, you might create commits such as:
Add payment form
Add payment validation
Connect payment API
Handle payment errorA commit represents a meaningful change, not necessarily the completion of the entire feature.
Whether unfinished work should be pushed depends on the team's habits, but many teams do push unfinished branches because GitHub can act as a remote backup and other developers can see the progress.
Avoid Doing Everything Directly on main
For a tiny personal practice project, working directly on main may be acceptable.
In a team environment, however, a more common workflow is:
main → Create branch → Develop → Push → Pull Request → Merge back to main
This helps keep main relatively stable while unfinished work stays on separate branches.
Keep Commit Messages Clear
Good Git collaboration is not only about using the right commands. Clear commit messages also make the project easier to understand.
Useful examples include:
Add login validation
Fix profile image upload
Update search API endpoint
Remove unused payment codeLess useful examples include:
update
fix
new
test
finalWhen a project has hundreds or thousands of commits, meaningful messages become extremely valuable.
Practice
You are going to fix a bug that prevents profile pictures from updating. Provide a branch name and the full command template from updating main and creating the branch through reviewing, committing, and pushing.
A Simple Workflow Template
For beginners, this is a useful template to remember:
git switch main
git pull
git switch -c feature/my-featureAfter doing some work:
git status
git add .
git commit -m "Describe the change"
git push -u origin feature/my-featureContinue working on the same branch with:
git add .
git commit -m "Another change"
git pushThen open a Pull Request on GitHub.
This workflow does not use advanced Git features, but it is enough for many everyday development tasks.