Git tracks changes to files in a folder called a repository. You do not need to know its internals to use it well. You need a small set of commands, used in a steady rhythm.
The daily loop
git statusshows what changed and what is staged. Run it often.git add <file>stages the changes you want in the next commit.git commit -m "clear message"saves a snapshot with a message that says why.git log --onelinelists the history, one line per commit.
Branches
A branch is a line of work. Create one for each change so the main line stays clean.
git switch -c fix-login # ...make changes, add and commit... git switch main git merge fix-login
git switch changes branch. The -c flag creates the branch first.
Sharing work
git pull brings in changes from the remote. git push sends your commits up. On a new branch, the first push needs git push -u origin fix-login so later pushes know where to go.
Undoing safely
- Before a change is committed,
git restore <file>throws away local edits to that file. - After a commit,
git revert <commit>makes a new commit that undoes it. It keeps the history honest. git reflogshows where HEAD has been, which is the way back from most mistakes.
Rule of thumb: never rewrite history that someone else has already pulled. Reverts are the safe choice on shared branches.
Next step
Want to practise this in a live batch?
We run these labs step by step.