GIT BASICS: UNDERSTAND VERSIN CONTROL, TRACK CHANGES, PUSH AND PULL CODES FOR BEGINNERS
Source: Dev.to
Git Bash
Git simplifies version control by letting you save snapshots of your code, collaborate safely, and revert mistakes easily.
What is version control?
Version control is a system that helps you:
- Track changes made to files over time.
- Go back to previous versions if something breaks.
- Collaborate with others without conflicts.
What are Git and GitHub?
- Git – a tool installed on your computer that tracks changes in your project.
- GitHub – an online platform where you store Git repositories and collaborate with others.
Key terms to know
- Repository – a folder where Git tracks your project’s history.
- Working directory – where you edit your files.
- Staging area – where you prepare files before you permanently save them.
- Commit – a snapshot of your project at a specific point in time.
Setting Up Git
First, confirm the version of the installed Git Bash:
git --version

Configure your name and email:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Generate an SSH key
An SSH key is a secure access credential.
ssh-keygen -t ed25519 -C "you@example.com"
-tspecifies the key type (ed25519is a secure encryption method).-Cadds a comment (usually your email).
This generates a private key (id_ed25519) and a public key (id_ed25519.pub). The public key will be linked to GitHub.
Start the SSH agent
eval "$(ssh-agent -s)"
Add the SSH key to the agent
ssh-add ~/.ssh/id_ed25519
Copy your public SSH key
cat ~/.ssh/id_ed25519.pub
Add the SSH key to GitHub
- Go to GitHub → Settings → SSH and GPG keys.
- Click New SSH key, give it a title, paste the copied key, and click Add SSH key.
Tracking your changes
Git tracks changes in three stages: working directory, staging area, and commit history.
Working directory
The working directory holds all project files as they appear on your computer. You edit files here.
Steps to create a repository
mkdir my-first-repo # Create a new folder
cd my-first-repo # Enter the folder
git init # Initialise Git (turns the folder into a repository)

Create a file:
touch README.md

Staging
When you modify a file, Git knows about the change but does not yet include it in the next snapshot. Stage the files you want to commit:
git add README.md
Commit
After staging, create a commit with a descriptive message:
git commit -m "Add README.md file"

Add the GitHub repository as a remote (replace with your actual URL):
git remote add origin git@github.com:username/repository-name.git
git remote -v # Verify the remote
How to Push Code to GitHub
git push -u origin main
origin– the name of the remote repository.main– the branch you are pushing to.
How to Pull Code from GitHub
git pull origin main
Use this when:
- Working on multiple branches.
- Collaborating with a team.
- Updating your local project with remote changes.
Git workflow
- Edit files.
git add→ stage changes.git commit→ save changes.git push→ upload to GitHub.git pull→ download updates.
Conclusion
Git may seem daunting at first, but it is an essential tool for developers. By mastering add, commit, push, and pull, you’ve covered the core workflow and can now apply Git daily.