Essential Git Bash Commands for Pushing and Pulling Code on GitHub
Source: Dev.to
What is Git Bash
Git Bash is a command‑line interface that lets you run Git commands on your local machine. It’s not GitHub, it’s not a programming language, and it’s not optional if you want to use Git from the terminal. Git Bash is simply the environment where Git commands are executed.
You use Git Bash every time you want to pull code from GitHub or push your local changes back to it.
How to set up Git Bash
Before you start working on anything, configure your Git identity.
Set your username
git --config global user.name "yourname"
Set your email
git --config global user.email "your email"
Git uses this information to link your commits to your account.
Getting a Repository into Git Bash
1. Cloning an existing GitHub repository
If the project already exists on GitHub, clone it with:
git clone
This command downloads the project to your local machine and creates a local repository.
2. Using Git Bash inside an existing local project
If the project already exists on your computer, initialize a repository:
git init
Then connect it to a remote GitHub repository:
git remote add origin
The Core Workflow: From Local Changes to GitHub
Check the current state of your project
git status
git status shows which files have changed and which are untracked. Run it before pulling, committing, or pushing.
Pulling code from GitHub
Pulling always comes before pushing. It downloads changes from GitHub and applies them to your local code, preventing conflicts.
git pull origin main
Replace main with your branch name if needed.
Making changes locally (before pushing)
Stage your changes after editing:
git add
Pushing code to GitHub
Send your local commits to GitHub:
git push -u origin
Common Push and Pull Errors
- Rejected – Happens when you try to push without pulling first. Pull before you push.
- Authentication failed – Git can’t verify your identity.
- Nothing to push – Occurs when you haven’t committed any changes.
Correct Push–Pull Order
For beginners, master this sequence:
- Pull
- Change
- Add
- Commit
- Push
Following this order keeps your code in sync, prevents rejected pushes, and minimizes conflicts.
Conclusion
Understanding Git might seem hard at first, but it gets easier with practice. You don’t become proficient by memorizing commands; you improve by running them repeatedly on real repositories, making mistakes, and reading the errors. Once you start moving, Git Bash becomes predictable.