git is a popular version control system that was created by Linus Torvalds in 2005
it is used for:
- tracking code changes;
- tracking who made changes;
- coding collaboration
- repository: a directory where git tracks your project and its history;
- clone: make a copy of a remote repository on your computer;
- stage: tell git which changes you want to save next;
- commit: save a snapshot of your staged changes;
- branch: work on different versions or features at the same time;
- merge: combine changes from different branches;
- pull: get the latest changes from a remote repository;
- push: send your changes to a remote repository
the staging environment (or staging area) is an environment (or an area) where you can "place" your changes (meaning files or directories) for the next work with them
this gives you control over what goes into your projects history (like if you want to show all your files/directories/features now or later)
well, staging is some sort of a proccess when you select something you want to work with into a staging area
for education purposes, you can imagine commits like saves in video games: when you think you need to save your job, you are using commits (or stashes, will describe them a little bit later)
it records a snapshot of your files at a certain time, with a message describing what changed
and, because commits are some sort of saves, you can always go back to a previous commit if you need to
also, it is a good practice to usegit commit -m "message"for short messages, andgit commitfor long messages: this will invoke a text editor that you setted up ingit config --global core.editor "editor"
and, once again, it is a good practice to keep your commits:
- short (50 characters or less) to increase readability;
- use the imperative mode (e.g., "add feature", not "added feature");
- if your commit is long, leave a blank line after the summary, then add more details if needed;
- describe why the change was made, not just what changes
for yourself, you can imagine tags like a bookmark or a label for a specific commit
tags are most often used to mark important points in your project history, like releases (v1.0,v1.5.5, etc)
tags are simple and reliable way to keep track of versions and share them with your team or users
some common tag types:
- releases: tags let you mark when your project is ready for release, so you (and others) can always find that exact version later;
- milestones: use tags to highlight major milestones, like when a big feature is finished or a bug is fixed;
- deployment: many deployment tools use tags to know which version of your code to deploy;
- hotfixes: if you need to fix an old version, tags make it easy to check out and patch the right code
lightweight tag:
just a simple name for a commit (no extra info, like an actual bookmark)
annotated tag:
stores author, date and a message
stashes let's you quickly save your uncommitted changes (if you need to fix bug or something else) and return to a clean working directory
common use cases:
- switch branches safely: save your work before changing branches;
- handle emergencies: stash your work to fix something urgent, then restore it;
- keep your work-in-progress safe: avoid messy commits or losing changes;
if you type
git stash, this will stash all your tracked files
if you typegit stash -u, this will stash both your tracked and untracked files
tracked files in git are files that git is aware about: you used them in previous commit (
git commit)
stashed files in git are tracked files that have been marked for inclusion in the next commit (git add)
to make your stashes clear and understandable, you need to follow some rules:
- use clear messages when stashing:
git stash push -m "message"- don't use stashes as long-term storage—commit your work when possible
- check your stash list regularly and clean up old stashes you no longer need
git history is useful for tracking who and when made this change, so if something broke, you can find a working version
some good practices:
- make frequent, meaningful commits to keep your history clear
- write clear commit messages so you and your team can understand changes later
- use
git log --onelinefor a quick overview of your commit history- use
git diffbefore committing to review your work
use
git log --author="Author"
use
git log --since="2 weeks ago"
and, if you want to see a simple ASCII graph of your branch history, usegit log --graph(it looks pretty good, idk what more can I say)