Git Basics for Beginners: Key Commands You Need to Know
What is Git?
Gate is a version control system which means it helps devs track their changes in their code.
Git is a distributed version control system which means
Every dev has complete copy of the project
Changes can be tracked without Internet
Work can continue even if central server is down
Why is Git Used?
Before Git devs used folders like final, final_v2, final_latest
This caused problems
Code got overwritten
No history of changes
Difficult to collaborate
No undo option if something broke
Git solved all this problem by
Tracking every change
Allowing teams to work together
Letting dev go back Previous version
Making collaboration safe and easy
Git Basics and Core Technologies
Repository(Repo)
A repository is a project folder that is tracked by git. Once a folder becomes a git repo, it starts monitoring all the files inside it.
Commit
A commit is a saved snapshot of our code.
Every commit has
a. A unique id
b. Author name
c. Date and time
d. A commit message is explaining What changes were made in this code
Branch
A branches separate line of development. Main or master is the default branch. We Create new branches to work on different features without disturbing the main flow.
Head
It points to the current commit that we are working on
Common Git Commands with Example
git initThis command creates a hidden folder named .git and starts monitoring the project.
git statusShow the current status of files. It tells us which files are new, which files are modified and which our files are staged.
git add <filename>Staging a file for commit
git add .Stage all changed and untracked files for commit
git commit -m ”commit message”Save all stage changes with a commit message explaining what we did.
git logShows are commit history. We can see our commit IDs, author Date and commit messages.
Closing Statement
Git may feel confusing at first. But we learned what git is and why it is widely using software development. We also covered git concepts like repository, commit branches and head. And explored git commands used in day to day work.