Below is a concise, ordered explanation of a typical Git workflow covering the most common local and remote operations.
1
Create a branch and make changes
Get into your project and create a new branch (example name shown):
gitcheckout-bnew_branch
Work on your code locally on that branch.
2
Stage changes
Move changes from the working tree to the staging area:
gitadd<files-or->.
This prepares files to be committed.
3
Commit changes
When staged changes are ready, commit them to your local branch:
gitcommit-m"Your commit message"
This moves staged changes into your local repository.
4
Push to remote
Push your local branch to the remote repository:
gitpushoriginnew_branch
This sends your local commits to the remote repo (e.g., GitHub).
5
Fetch and integrate coworkers' changes
To fetch updates from the remote (without merging them into your working tree):
gitfetch
After fetching, inspect the incoming changes and integrate them using either:
Merge:
gitmergeorigin/other_branch
Or rebase:
gitrebaseorigin/other_branch
Choose merge or rebase depending on your workflow and history preferences.
6
Pull (fetch + merge in one)
If you want to fetch and immediately integrate the remote changes into your current branch:
gitpull
Note: This is equivalent to git fetch followed by git merge (unless you configure a different behavior).
7
Switch branches (checkout)
To switch to another existing branch or create-and-switch:
Switch to existing:
gitcheckoutsome_branch
Create and switch:
gitcheckout-banother_branch
This changes your working tree to the target branch so you can continue working locally.
git fetch + git merge is the explicit two-step approach that lets you review incoming changes before integrating. git pull combines both steps and is faster when you trust the incoming changes.