DEV Community

Benta Okoth
Benta Okoth

Posted on

Git Essentials for Beginners

Overview

This guide introduces beginners to the core concepts of Git, the leading version control system.
You’ll learn what version control is, why it matters, and how to track file changes.
Step‑by‑step, we’ll cover staging and committing work to build a clear project history.
You’ll also see how to push code to GitHub and pull updates to stay in sync.
By the end, you’ll master the everyday Git workflow: track → commit → push → pull.

Git Bash vs GitHub

Git Bash - A command-line tool on your computer used to run Git commands (clone, commit, push). It works locally, basically where you type commands.
GitHub - An online platform (website) used to store, share, and collaborate on Git repositories in the cloud. Basically where your code is stored and shared online

Importance of Git

  1. Version control – Tracks changes and allows rollback to earlier versions
  2. Cloud backup – Code is safely stored online
  3. Collaboration – Multiple people can work on the same project
  4. Portfolio building – Showcases skills to employers
  5. Code review – Improves quality through pull requests and comments
  6. Industry standard – Widely used across tech and IT roles

Git Bash Installation

  • Go to the Git website: https://git-scm.com/install/windows and install the git bash
  • Go to the search bar and search for git bash, to check if the installation is complete.
  • Click on the git bash icon and the git command line will be opened.

Connecting Git Bash to a GitHub Account

1.Checking the installed Git Bash version using a command

git –version

2.Configure identity on git bash

  • we config name and email as below
  • git config --global user.name "name"
  • git config --global user.email xxxx@gmail.com

3.Confirmation of the name and email by check the list
git config --global –list

4.Using SSH Key and How to Generate an SSH Key

  • - >> ssh-keygen -t ed25519 -C "email@gmail.com"
  • - >> Enter file in which to save the key (/c/Users/Lenovo/.ssh/id_ed25519):
  • -(dont enter anything just press enter and then enter again, ssh key will be populated)
  • We need an agent (the key holder) - this is what holds the key generated we use the command is

eval "$(ssh-agent -s)"

  • eval (builtin command and its role is check and helps to push a text command ie in python it’s the string)
  • ssh-agent = a helper program that holds your keys in memory
  • -s = output commands in a format the shell can use
  • $(...) = “run this command first, and insert its output here”
  • eval = “execute the text that comes out”

5.Add your SSH private key (id_ed25519) into the SSH authentication agent (ssh-agent)

  • This helps Git (or any other tool using SSH) to use it automatically without asking for your passphrase every time. The command is below :

ssh-add ~/.ssh/id_ed25519

  • These tells us the identity has been added as below Identity added: /c/Users/Lenovo/.ssh/id_ed25519 (email@gmail.com)"

6.When need to see our public key then use it to connect to github

  • We need to print it using the command (when using the ssh) cat ~/.ssh/id_ed25519.pub

7.Add the Key to GitHub and Test the Connection

  • Go to GitHub on your browser > Settings > SSH and GPG Keys and then name and then copy the key plus the email from git bash and add it.

ssh -T git@github.com

GITBASH AND GITHUB WORKFLOW

  1. Create and Move to a Project Folder
  • You start by making a directory and get to the directory using the commands below

mkdir my-first-data-project

cd my-first-data-project

2.Git Tracking/Initialize the Folder using the command

git init
(this helps turn your folder into git repository)

3.Create a New file in Folder created earlier on using the command
touch Week1.html - creates an empty file

echo "print python" > Week1.txt - This creates a file called Week1.txt with the text print python inside.

nano readme.md or >> vim script.js - This opens the file in a terminal-based editor. Save and exit when done.

4.Confirm the file exists using the command
ls

5.File Tracking, Modifications and Changes Saving
We use the command

git add - to help save the changes (moves the changes to the staging area) done

git commit - to help actually creates the snapshot of your project history. Takes everything you staged with git add and saves it permanently in Git’s timeline, along with the message you write. Commit message are usually the words in quote after the -m which acts as a label helps to be able to identify what changed and at what time.

git add > select changes to include
git commit > save those changes into history

6.Checking History of Snapshot
We use the command
git log
Shows all commits in detail (author, date, commit message, commit ID) as below.
Press q to quit the log view.

7.Publish your work to the repository / Upload your code to GitHub

  • Go to the github and create the repo with the exact name of the one created on gitbash ie my-first-data-project

  • Then ensuring we are in the folder on the git bash side
  • Connect your local project to the github using the command

git remote add origin https://github.com/your-username/my-first-python-project.git

Then Push your work using
git branch -M main
git push -u origin main

Then going forward you will use
git push

8.Get Changes from Others/Another Computer (Pull)
git pull

Top comments (0)