Git Workflow provides essential version control capabilities for managing codebase changes cleanly, predictably, and efficiently.
git restore, git reset, git commit --amend)See Also: GitHub Flow is a popular collaborative workflow for teams using GitHub.
If you work with GitLab or Bitbucket, those platforms have their own workflows too. Learn more about GitHub Flow »
Git uses a distributed workflow that allows you to work on your code, stage changes, and commit them to your local repository before sharing with others.
Understanding this workflow is essential for effective version control.
Working Directory : Where you make changes to your files.
Staging Area (Index) : Where you prepare changes before committing.
Repository : Where your committed history is stored.
Workflow Diagram
[Working Directory] --git add--> [Staging Area] --git commit--> [Repository]
git status to avoid surprises.git add <file> for precision.git diff before committing.This is where you make changes to your files.
Think of it as your workspace or desk.
Files here can be new, modified, or deleted, but Git won't save these changes until you stage and commit them.
git add)When you are happy with your changes, you "stage" them with git add.
This puts your changes in the Staging Area, like putting your finished letter in an envelope.
Example
git add index.html
To stage all changes (new, modified, and deleted files):
git add .
git commit)Committing saves your staged changes to your local repository.
It's like mailing your letter-you can't change it after it's sent!
Example
git commit -m "Describe your changes"
You can also use git commit -a -m "message" to stage and commit all modified and deleted files in one step (but not new files).
git push)After you commit, your changes are only in your local repository.
Use git push to send your commits to a remote repository (like GitHub or Bitbucket) so others can see them.
Example
git push
git status)Use git status to see which files are staged, unstaged, or untracked.
This helps you keep track of what you still need to add or commit.
Example
git status
Made a mistake? Git lets you fix things before you push!
git restore <file> - Undo changes in your working directory (before staging).
git restore --staged <file> - Unstage a file (move it out of the Staging Area).
git reset HEAD~ - Undo your last commit (keeps changes in your working directory).
git commit --amend - Change the last commit message or add files to your last commit.
Example: Unstage a file
git restore --staged index.html
git status often to see what's going on.git reset or git commit --amend before pushing.git add <filename> for specific files.Execute the following terminal commands to work with this concept in your workspace:
# Check repository status
git status
# View formatted log
git log --oneline -n 5
Fix CORS bug rather than Fixed CORS bug).git diff to review unstaged modifications before adding files to the index.git switch -c <branch-name> to preserve edits.git restore --staged <filename> to remove the file from the index without altering your local workspace copy.Open your terminal in a test project directory, execute git status, and verify your current working tree state. Practice running git log --oneline to review commit history.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With