Git Workflow
🎯 Start Here
You've learned individual Git commands—but how do they all fit together in practice? Professional developers follow a consistent workflow every day: make changes, stage, commit, push, pull. Understanding this flow is what separates knowing Git commands from actually using Git effectively.
- What steps do you currently take when you finish working on a feature?
- How do teams keep their code in sync when multiple people are working at the same time?
Let's put everything together into the workflow you will use every day as a developer.
Learning Objectives
By the end of this lesson, you'll be able to:
- ✓ Understand Understand the typical Git workflow
- ✓ Use Git commands to stage, commit, push, and pull changes
- ✓ Collaborate with others using Git
Why This Matters:
The Git workflow is the daily routine of every professional developer. Mastering it makes collaboration seamless and keeps your projects organized.
Before You Start:
You should be familiar with:
- Be familiar with basic Git commands
- Understand Git branching
- Know how to connect to a remote repository
What is a Git Workflow?
A Git workflow is a series of steps that developers follow to manage changes in a project. It ensures that everyone on the team can collaborate effectively and that changes are tracked and versioned properly.
The typical Git workflow involves the following steps:
- Making changes to files in your working directory
- Staging the changes to prepare them for a commit
- Committing the changes to save them in the local repository
- Pushing the changes to a remote repository
- Pulling changes from the remote repository to stay up-to-date
Step 1: Make Changes
Start by making changes to the files in your project. These changes will be in your working directory and are not yet tracked by Git.
Step 2: Stage Changes
Use the git add command to stage the changes you want to include in your next commit. For example:
To stage all changes, use:
Step 3: Commit Changes
Once your changes are staged, use the git commit command to save them in your local repository. For example:
The commit message should briefly describe the changes you made.
Step 4: Push Changes
The git push command uploads your local commits to the remote repository. This allows others to access your changes and ensures your work is backed up remotely.
The syntax git push origin main means:
origin: The name of the remote repository (default name when you add a remote)main: The branch you want to push your changes to
For example, the following command pushes your local changes to the main branch of the remote repository:
After the first push, you can simply use git push if the upstream branch is already set.
Step 5: Pull Changes
The git pull command fetches changes from the remote repository and merges them into your local branch. This ensures your local repository is up-to-date with the latest changes made by others.
The syntax git pull origin main means:
origin: The name of the remote repositorymain: The branch you want to pull changes from
For example, the following command fetches changes from the main branch of the remote repository and merges them into your current branch:
If there are conflicts between your local changes and the remote changes, Git will notify you and require you to resolve the conflicts before completing the merge.
Collaborating with Others
When working with a team, it's important to communicate and coordinate changes. Here are some tips for effective collaboration:
- Pull changes from the remote repository before starting new work
- Use branches to work on new features or bug fixes
- Write clear and descriptive commit messages
- Resolve merge conflicts promptly
Setting Up Git in VS Code
Visual Studio Code has built-in Git support, making it easy to manage your repositories directly from the editor. Follow these steps to set up Git in VS Code:
Step 1: Open the Source Control Panel
Click on the Source Control icon in the Activity Bar on the left side of the editor. If you have a Git repository initialized in your project folder, it will automatically appear here.
Step 2: Configure Git in VS Code
If you haven't already configured Git globally, VS Code will prompt you to set your name and email. You can also configure it manually by running the following commands in the integrated terminal:
Step 3: Commit Changes
To commit changes, stage your files by clicking the icon next to the file name in the Source Control panel. Then, enter a commit message in the text box and click the checkmark icon to commit.
Step 4: Push and Pull Changes
Use the Source Control panel to push your changes to a remote repository or pull changes from it. You can also use the integrated terminal to run git push and git pull commands.
Step 5: View Git History
Install the Git History extension to view your commit history in a visual format. This can be helpful for tracking changes and understanding your project's timeline.
Try It Yourself
Use the interactive terminal below to practice the Git workflow:
🏁 Lesson Complete: Git Workflow
Key Takeaways:
- The Git workflow is: make changes, stage, commit, push, and pull
- Always pull the latest changes before starting new work
- Use branches for features and bug fixes, then merge when done
- Write clear, descriptive commit messages for every commit
- Resolve merge conflicts promptly to keep the team moving
Learning Objectives Review:
Look back at what you set out to learn. Can you now:
- ✅ Understand the typical Git workflow Check!
- ✅ Use Git commands to stage, commit, push, and pull changes Got it!
- ✅ Collaborate with others using Git Can explain it!
If you can confidently answer "yes" to most of these, you're ready to move on!
Think & Reflect:
💭 💭 Reflection Questions
- How does this workflow compare to how you currently manage your projects?
- What part of the Git workflow do you think you will use the most?
- How would you explain this workflow to a teammate who has never used Git?
🎯 Looking Ahead:
You've now learned the complete Git workflow! Head to the conclusion to review everything you've learned across the entire Git Basics series.
Recommended Next Steps
Related Topics
Explore these related tutorials to expand your knowledge:
Practice Projects
Apply what you've learned with these hands-on projects:
Additional Resources
Deepen your understanding with these helpful resources:
- Git Best Practices - A collection of best practices for using Git.
Progress tracking is disabled. Enable it in to track your completed tutorials.
Cookie Settings