Page 2 of 2
Once work on a branch is done, you bring it back into another branch (usually main) with a merge.
git checkout main
git merge feature-login
If main hasn't changed since you branched off, Git does a fast-forward merge - it just moves the main pointer forward to your latest commit, no new commit needed. If main has moved (someone else merged something), Git creates a merge commit that ties both histories together, with two parent commits instead of one.
Understanding this distinction matters later: a fast-forward merge leaves a perfectly linear history, while a merge commit visibly shows where two lines of work rejoined.
Not everything in a project folder belongs in version control - build output, dependency folders, editor settings, secrets. A .gitignore file tells Git what to never track:
node_modules/
*.log
.env
dist/
git status # ignored files simply won't show up as untracked
If a file is already tracked before you add it to .gitignore, ignoring it won't stop Git from tracking it - you have to explicitly remove it from tracking (git rm --cached) first. This surprises a lot of people the first time.
Mistakes are routine, and Git has gentle ways to undo the common ones at this stage.
git restore file.txt # discard uncommitted changes to a file, back to last commit
git restore --staged file.txt # unstage a file without discarding your edits
git commit --amend # fix the message (or add forgotten changes) to your last commit
git restore is the newer, clearer replacement for older checkout-based undo commands, and it's worth learning first because the split between "discard my edits" and "just unstage" maps directly onto the three-states idea from earlier. Deeper undo tools - resetting whole commits, reverting pushed history - come later once you understand why they need more care.
Real scenario-based DevOps questions, hands-on practice, and clear explanations for every answer.