Control and Tracking of code or any file changes over time
Saving progress as you go
To have backup files to get back to if any problems/bugs arises
Avoid writing multiple side copies of files for every draft
In version management, its easier to jump back and forth to any draft in single file
Git & Github
Git is Version Control System, manages code history, tracks changes and is a local tool.
Github is Largest Development Platform, Cloud Hosting & Collaboration Provider, Git Repository(Git Project) Hosting.
Text Based Computer Interaction (bash, zsh)
Time Saving, start servers, download & install tools, run code, execute files, working with git.
Where our project is
Change Directory
Create and Delete files and folder
Copy and move
For Command Prompt (cmd) on Windows
How Git Works(Simplified)
Working directory
web shop
|_index.html
|_styles.css
|_images
|_..
Commit
Commit creates snapshots.
1st commit to create snapshot 1.
After changing the content of css file, 2nd commit is made creating snapshot 2.
Here 2 copies of css files are not created. Git only checks the initial state of css in first commit and checks what changes has been applied to this file now. Only these information are stored in git.
Git stores all changes made throughout the project in a branch called master(or main) by default.
Under the hood
.git folder is created on the working directory which is a hidden folder.
.git contains two areas staging area and commits(objects folder)
Changed Files are added to staging area to tell git that they are part of next commit.
Now committing will add the changed files to Commits area.
Git tracks changes but does not store files again and again. Only in the initial commit, files are saved and after that, changes are saved.
Git Commands
Branches & Commits
We can create copy of the master(or main) branch to create a new branch where changes can be made without touching the main working directory.
Merging branches
What is HEAD?
Head
Suppose master has 3 commits: c1, c2, c3
Now we create a new-branch, So the head now refers to c3(commit from where new branch is created).
Detached Head
In above example, if we checkout c2 which exists in both master and new-branch, the head is no longer in specific branch but is detached in two branches.