If you are like me, using gitbash was a nightmare for the first time.
Most beginners don’t struggle because Git is “too complex.” They struggle because they don’t know:
-Which command to run,
-In what order,
-And what each command actually does.
If you are interacting with gitbash for the first time,don't worry, because in this article, i will help you understand how towork on GitHub using Git Bash — confidently and without guessing.
What is Gitbash
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 Gitbash
This is a very important step before you start working on anything.
You need to configure 2 things:
-Your git username
-Your git email
To configure your user name you will use this command:
git --config global user.name "yourname"
And, to for your email, this is the right command to use:
git --config global user.email "your email
This is very important because everytime you want to work on anything Git uses this information to link your commits to your account.
Getting a Repository into Git Bash
This is where most beginners get confused. There are only ways to go about this:
-1. Cloning an Existing GitHub Repository
This works if there is an already existing project on github that you want to clone. To do this, we use this command:
git clone <repository-url>
This command downloads the project to your local machine and creates a local repository.
-2. Using Git Bash Inside an Existing Local Project
This works when the project exists on your local computer. To work on it, you innitialize git using:
git init
This command creates a local repository which is not yet connected to github, to connect it:
git remote add origin <repository-url>
And this works when you build projects locally and you want to push them to Github
The Core Workflow: From Local Changes to GitHub
To work seamlessly on github, there are things you need to learn, if you miss this, working on github will prove to be a nightmare.
To check the current state of your project
Before doing anything, run this to check the current status of your project:
git status
This commands helps you know which files changed and which ones are untracked. Its very important to run this command before you pull, before you commit and before pushing.
Pulling Code from GitHub Using Git Bash
Pulling always comes before pushing. Git pull downloads changes from github and applies them to your local code which prevents conflitcts.
To pull changes:
git pull origin main
You can replace main with your branch name if needed.
You pull when you have a project you want to start working on or when you want to push your own changes.
How to Make Changes Locally (Before Pushing)
You cannot push raw file changes, git only pushes commits. To stage a change after editing changes, use:
git add
Pushing Code to GitHub Using Git Bash
This is where beginners aim at. What gitpush does is that it sends your local commits to github, here is the basic push command:
git push -u origin <branch-name>
What Are The Common Push and Pull Errors
- Rejected - this happens when you try to push without pulling first. The right order is to pull then push first.
- Authentication failed - This happens when git can't verify its you. -Nothing to push - This will happen when you didnt commit anything.
The Correct Push–Pull Order
As a beginner there is a sequence you need to master, in this order:
Pull, change, add, commit, push.
This order is very inportant as it keeps your code in sync, prevents rejected pushes and minimizes conflicts.
Breaking this order will lead to errors everytime.
Conclusion
Understanding git might seem hard when you are starting, but it gets easier and better with time.
You dont get good at it by memorizing commands.You perfect by running the same commands on different real repeatedly.
The aim as a beginner should be to practise with actual repositories, make mistakes, read the errors and git will start making sense.
Once you start moving, Gitbash starts feeling predictable.
Top comments (0)