Basics of Git
What is Git?
Git is used to track different versions of files. It is useful for group projects, ensuring that everyone can work on it without overwriting each other. Think of it as the tracker of the multiverse versions of your files; it can manipulate the timelines.
Why Learn it?
- It makes it a lot easier to keep track of changes between people.
- Easy to back up
- You can rollback changes that broke something
Essential Git Concepts
Repository (Repo)
A project folder that Git watches. It contains all the files in your project and their histories. Can be local or put on remote platform like GitHub/GitLab.
Commits
A commit is a snapshot that you make of committed files at a specific point in time. The basic structure of a commit contains:
- unique identifier (hash)
- timestamp/author
- commit message describing what was changed (VERY IMPORTANT)
You can think of them as saves in the video game that can go back to.
Branches
Branches work exactly like the parallel universes you see in movies. When you want to work on a major feature (by adding commits), you would typically create a new branch.
Create new branches to:
- add a new feature
- fix a lot of bugs
- experiment with something
There is a bit more specifics of branches later.
Common Workflows
This section describes the general overview of how git would be used without getting into the specifics on commands, those will come later.
Starting a new project
- Create a repo on GitHub
- Clone it to your computer (follow instructions it shows you)
- Add your files
- Commit and push changes to remote repo
Working on existing project
- Clone repo
- Create a new branch for your feature
- Make your changes, commit regularly
- Push your branch to remote
- Create pull request to merge into master
Best Practices
- Commit often, this allows for rolling back changes This is still within reason, like don't commit grammar changes to comments separately
- Write clear commit messages Explain what you did so the owner of the repo can tell what's going on
- Use branches in a group setting Don't work directly on master, it's only for stable features