[Lecture 0] Introduction to Git
- Git
- What is git?
- It is a Distributed Version Control System.
- What is Version Control System - it is a software which lets you track changes over time and recall specific versions later
- Why do you even need such a functionality to track versions
- Imagine you are playing a game and whenever you fail a mission you are reverted to the start of the game just because the game didn’t save any checkpoints. Isn’t that annoying?
- So to prevent that, the game save checkpoints (versions) to give a better experience to the user.
- Extrapolating this concept to code, let’s suppose a software (say Android) has multiple versions. And when you start developing and adding new feature and somehow you managed to break the whole code. How will you revert? How many times will you undo!? This doesn’t seem a plausible solution.
- This is why you have multiple versions of the software so you can go to a place where everything was working.
- What changes will git bring to your project if you integrate it?
- Use
git init
to initialize an “empty git repository” in your project.
- You will simply notice a .git folder in your project.
- It basically divides your project into 3 parts:-
- Working Directory
- Normal editing. Git keeps track so that if you mess up, you can revert.
- You can modify/create files here.
- Staging area
- Use
git add
to stage the files from working directory to staging area.
- Files which are sent here are intended to be a part of the next version.
- After deciding which all files can be the part of the next commit/version, use
git commit -m
to create a new commit or a version of the project.
- Repository
- This is the part which stores all versions or commits.
- You may now push it on GitHub using a command
git push
- Usage of
git pull
and git clone
.
- Host it on GitHub
- How to share with others if one wants to collaborate?
- Pendrive may not be a very good idea. :P
- We use GitHub to host our projects online.
- Anyone who is interested may “join” our project and start developing.
- Branching in Git and why?
- To introduce a bug-fix/feature or simply experiment.
- So that you can easily get back to the working version.
- Simply create a branch using
git branch -b <name>
.
- Collaboration
- Distributed means that every developer who clones this project will have access to all files and their respective version.
- Discuss why working on Master may not be good idea.
- Ideal workflow.
- Tell them about
git rebase
- Tell about .gitignore