DEV Community

Cover image for Version control - Git and Github
Jesse Ngugi
Jesse Ngugi

Posted on

Version control - Git and Github

PART 1 - What are Git and Github

Git - is a program installed on your computer. It tracks changes to your files over time. (infinite “undo” history of a project) - (lives on your machine)

Github - is a website that stores a copy of your Git project “in the cloud” , so you can back it up, share it, and work on it with other people (collaboration) - lives on the internet

Why it matters.

Before git, teams shared code by emailing zip files. Git solves these problems:
● History - see every past version of every file and who changed what
● Collaboration - multiple people can work on the same project without overwriting each other
● Safety - you can experiment freely(in a branch) without breaking main project.

PART 2: Telling Git who you are

  • Git attaches an author name (username) and email to every change (a “commit”).
git config --global user.name "Your Name" 
git config --global user.email "your.email@example.com"
Enter fullscreen mode Exit fullscreen mode

Why it matters:

  • When you collaborate, everyone needs to see who made which change. (this is how Git labels your work)

PART 3: Core concepts

Core concepts of git

The three States of a file

State and What it means

Working Directory - Git doesn't know about the changes yet

Staging area - Ran(git add) - Git knows, but hasn’t saved permanently - “cart” “waiting room”

Repository - You have run (git commit) - permanently saved in history

Key terms

Repository (repo) - A project folder that Git is tracking
Commit - a saved snapshot of your project at point in time, with a message describing what you changed
Staging area - “waiting room” where you choose exactly which changes will go into the next commit
Remote - a copy of your repo hosted somewhere (GitHub)
Clone - downloading a copy of a remote repo to your computer
Branch - a separate, parallel line of work.
Pull - downloading new changes from Github (remote) into your computer
Push - Uploading your commits from your computer to GitHub
Pull request (PR) - is a request to merge your branch’s changes into another branch, with a chance for other to review first
Merge - combining the changes from one branch into another.

PART 4: YOUR FIRST PROJECT.

(my-first-project)

Step 1 - Create a local project folder

Step 2 - Turn it into a git repo

Turn it into a git repo

  • It create a hidden .git folder - this is where all of Git’s tracking data lives.

Step 3: Create a file

Creating a file

Step 4 Check status

Checking status

Git will show README.md as untracked ( git sees it exists but is not tracking it yet)

Step 5 - stage the file

Staging the file

Step 6- Commit the file
git commit -m “Initial commit: add README file”

  • -m message should describe what changed.

PART 5: The daily loop

This is the cycle you repeat constantly
● git status # see what changed
● git add . # stage changes
● git commit -m “message” # save a snapshot
● git push # upload to github

“If I merge these code it will?..........”

Top comments (0)