DEV Community

Mutuku joseph
Mutuku joseph

Posted on

A Beginner’s Guide to Using Git Bash and GitHub

Hey! So you want to get into tech—but you’re not sure where to start. You’ve heard terms like code, databases and they all sound important… and confusing. Don’t worry. This guide is built for beginners on github and git bash, focusing on clarity over complexity and progress over perfection. Lets dive in.

Basic definitions

Git Bash
Is a command line based module that developers use to manipulate projects on github. Through version control developers can work on several segments of the same project simultaneously without interrupting each other.
GitHub
Is a cloud based service where developers host projects and work on them collaboratively over the internet.
It allows allows developers to:
-store, manage and share projects
-collaborate on projects with others
-track changes made to files

Setting Up GitHub

Before using Git Bash, you need a GitHub account:

To get started on github, you need to
.go your browser of choice
.go the github website and sign up with your username and email to creat an account.
Use this link to create a github account; [https://github.com/]

Setting Up Git Bash

Next, let’s set up Git Bash on your computer which is our local host/repository:

To get started on git bash terminal;
. you go to the git bash website,
.download and install it on your computer.
Actually Git bash terminal comes included and ready for you to run git commands.
Use this link to download and install git bash;[https://git-scm.com/]

Git Bash lets you run Git commands and basic Linux commands right from your computer. Once installed, you’re ready to start managing projects.


Getting Started with Git Bash

Step 1: Check Git Version

Open Git Bash and type out:
git --version
This checks the just downloaded version of your git bash
This also confirms Git is installed.

# this is how you check the version
$ git --version
#or
git version
Enter fullscreen mode Exit fullscreen mode

Step 2: Configure Your Name and Email

Git needs to know who you are so it can track changes:

#This is how you setup your name on git
$git config --global user.name "Your Name"

#use this to setup your email on git
$git config --global user.email "your email"
Enter fullscreen mode Exit fullscreen mode

To check if the configuration worked use;
git config--global--list

$git config --global --list
Enter fullscreen mode Exit fullscreen mode

SSH key

Then go ahead and create a ssh key- an ssh key is a secure way to interact with git bash and github without needing a password everytime.

# this is how you generate an ssh-key
$.ssh-keygen -t ed25519 -C "email"

# then check whether key was generated
$ ls ~/.ssh 

# the turn the key into the SSH agent
$eveal "$(ssh-h-agent/-s)"

#then add the ssh key agent to git bash
$ssh-add~/.ssh/id_ed25519

Enter fullscreen mode Exit fullscreen mode

Creating Your First Local Repository

Think of a repository as a folder holds and tracks all your project changes.

  1. Create a folder for your project:
    mkdir folder1

  2. Move into the folder:
    cd folder1

# This is how you creat your repo in git
$mkdir folder1

#the change directory to that folder
$cd folder1
$git init
Enter fullscreen mode Exit fullscreen mode

Now this folder is your local repository, where you’ll work on files and save changes.


Creating a Remote Repository on GitHub

You also want a version online, so your work is backed up and shareable:

  1. Log into GitHub and go to Repositories.
  2. Click New repository, give it a name, and add a short description.

Later, you’ll connect this online repository to your local one so you can sync your work.


Initializing Git in Your Local Repository

Tell Git to start tracking your project:

git init

Create your first file:
touch "file name"

#once you cd to the current folder,you initialize 
$git init

$create a file 
$touch file1
Enter fullscreen mode Exit fullscreen mode

created files that are then saved on the main folder for easy access and are eventually pushed to github

Saving Changes with Commits

A commit is like hitting “save” in a video game—it creates a checkpoint, and you can always go back to that point.
This is because;
-git keeps track of all files changed and by whom
-git keeps track of times the change was made and has a message of the nature or reason for the change

Step 1: Stage Your Changes

$git add "file name"   

# used to add several files
$git add .
Enter fullscreen mode Exit fullscreen mode

Step 2: Commit Your Changes;

git commit -m "commit message"

git commit -m "commit message"
Enter fullscreen mode Exit fullscreen mode

Connecting Local and Remote Repositories

Link your local repository to GitHub:
we then have to connect out remote repository (github repo) to our locally hosted repository. This ensure that changes commited locally reflect on our github.

git remote add origin "YOUR_REMOTE_REPO_URL"
Enter fullscreen mode Exit fullscreen mode

Push your changes online:
The final stage is then to push the changes made from our local repository to our remote repository on github.

git push -f origin main
Enter fullscreen mode Exit fullscreen mode

Once you have created files and worked on them,its time to staging area

$git add "file name"
# or use for several files
$git add .
# commit the changes(move staging files to local repo)
$git commit -m "add commit message"

Enter fullscreen mode Exit fullscreen mode

Then add the changes to the local repo ready to push to guthub

$git remote add origin "github repo url"

push the changes to the remore repo

$git push -f origin main/master

$git remote add origin "github repo url"

$git push  -f origin main/master
Enter fullscreen mode Exit fullscreen mode

You can also do this using VS Code’s Source Control panel if you prefer a visual interface.

Pulling Changes from GitHub

When someone else makes changes—or when you switch computers—you’ll want the latest version of the project. This is called pulling:

git pull

To pull in this context is downloading a project file with the current chnages to your local host and working on them.
This command connects to the remote repository (github repo) to download and updates the local files

git pull
Enter fullscreen mode Exit fullscreen mode

Understanding Version Control

Version control is what makes Git powerful. It:

  • Tracks every change made to your files
  • Lets multiple people work on the same project safely
  • Helps you undo mistakes
  • Keeps a complete history of your project

Branching

A branch is a separate version of your project. You can experiment or add features without touching the main project. Once it’s ready, you merge it back.

git branch new-feature
git checkout new-feature
git merge new-feature

Tracking Changes

Git tracks changes in three steps:

  1. Local repository/working area – where you edit files
  2. Staging Area – where you prepare changes for saving (git add)
  3. Repository – where changes are permanently saved (git commit)

To check what’s changed use:

# to check changed files
$git status

# to check what was actually changed
$git diff
Enter fullscreen mode Exit fullscreen mode

Simple Visualization Git Workflow

Look at you now! All ready to kick it on git bash and git hub.

Post over there regulary and share widely for practice as always makes perfect. Lets go!

Top comments (1)

Collapse
 
avedi profile image
Owen Avedi

Very insightful