Notes
The idea
Git keeps your work in three places. The working tree is the files you are editing. The staging area holds the changes you have chosen for the next commit. The repository holds commits, which are saved snapshots of the whole project, each with a message, an author and an id. You move a change from working tree to staging with git add, and from staging into history with git commit.
- working tree: the files you are editing right now
- staging area: the changes you chose for the next commit
- repository: commits, the saved history
- a commit = a snapshot with a message, an author and an id
Everyday commands
The daily loop. Git clone gets a copy of a repository. Git status shows what changed, and git diff shows exactly which lines. Git add stages the files you want. Git commit with a message saves them. Git log with one line lists the history. A good habit for beginners: run git status before and after every command. It tells you where things are and usually suggests the next command.
git clone <url> # get a copy git status # what changed git diff # line by line git add src/test/... # stage git commit -m "Test SAVE10 at exactly $50.00 (PRICE-3)" git log --oneline # history run git status before and after every step
Good commits
Commits should be small, one logical change each, with a message that says what and why. Changes and fixed stuff help nobody. Add boundary tests for save ten, with the rule id, tells a reviewer exactly what to expect. Write in the imperative mood, add, fix, remove, and link the ticket or requirement. Six months later, when a test starts failing, a good history is how you find out why it exists.
- weak "changes"
- weak "fixed stuff"
- strong "Add boundary tests for SAVE10 (PRICE-3)"
- strong "Reset ShopRung data before each API test"
- one logical change per commit
- imperative mood: Add, Fix
- link the ticket or rule id
Branches
Never work directly on main, the branch everyone else runs. Switch to main, pull the latest, then create your own branch with git switch dash c and a descriptive name, like test slash save ten boundaries. Write and commit your tests there. Then push the branch to GitHub with git push dash u origin and the branch name. The dash u links your local branch to the remote one, so later pushes and pulls need no extra arguments.
git switch main git pull git switch -c test/save10- boundaries ... write tests, commit ... git push -u origin test/save10- boundaries main = what CI and the team run one branch per change
Pull requests
A pull request asks the team to merge your branch into main. Give it a clear title, what you changed, why, how to check it, and proof. For test code, the best proof is that the new tests fail with the bug switched on and pass with it off. The pipeline runs the suite automatically, and it must be green before merging. Small pull requests get reviewed quickly. Huge ones wait for days.
- title: Add SAVE10 boundary tests (PRICE-3)
- what: 4 parameterized cases 4999, 5000, 5004, 5005
- why: coupon-boundary bug escaped last release
- how to check: mvn test
- proof: fails with the bug on, passes with it off
- CI must be green
Reviews
Test code deserves real review. Does it test what its name says? Would it actually fail if the feature broke? Is it independent and repeatable? Any sleeps, hard coded secrets or addresses? Are names and failure messages clear? Comment on the code, not the person, and kindly. The author answers by pushing new commits to the same branch, and the pull request updates itself. Some teams squash the commits into one when merging.
- does it test what it says?
- would it FAIL if the feature broke?
- independent and repeatable?
- no sleeps, no hard-coded secrets or URLs
- clear names and messages
- comment on the code, kindly;
- fix with new commits
Conflicts
A merge conflict happens when two branches change the same lines. Git cannot guess which is right, so it marks the spot: your version above the equals signs, the other branch's below. Here one branch says free shipping starts at seventy five dollars and the other at eighty. Do not just pick one. Find out which is correct, maybe by asking, edit the file to the right result, delete the markers, then add and commit. IDEs show conflicts side by side, which helps.
<<<<<<< HEAD FREE_SHIPPING_FROM = 7500; ======= FREE_SHIPPING_FROM = 8000; >>>>>>> test/new-threshold 1. keep the right version (ask if unsure!) 2. delete the markers 3. git add + git commit
.gitignore
A dot gitignore file lists what Git must never track. Build output like target and node modules. Test reports and results folders. IDE settings. Log files. And above all, the dot env file where local secrets like passwords and API keys live. Secrets belong in the pipeline's secret variables or a local file that is ignored. Once a secret is pushed, assume it is leaked: rotate it, because deleting the file does not remove it from history.
target/ node_modules/ test-results/ playwright-report/ .idea/ .env *.log secrets go in CI variables or a local .env, never Git
Staying in sync
Stay in sync. Pull main often, and bring its new commits into your branch with git merge main, or git rebase main if your team prefers a straight history. Git stash parks unfinished changes so you can switch branches, and stash pop brings them back. And if you committed too early, git reset dash dash soft head tilde one undoes the last commit while keeping your files. Lab five walks through each of these on a real branch.
git switch main && git pull git switch test/save10-... git merge main # or: git rebase main git stash # park changes git stash pop undo the last commit, keep files: git reset --soft HEAD~1
Common mistakes
Git mistakes testers make. Committing straight to main. Git add dot with a secrets file or a report folder sitting there. Pull requests with forty files nobody wants to review. Messages like update. Force pushing to a branch other people use; if you must rewrite your own branch, use force with lease, which refuses if someone else pushed in the meantime. And resolving conflicts by blindly taking one side.
- committing straight to main
- git add . with secrets or reports in the folder
- huge PRs with 40 files
- messages like "update"
- force-push to a shared branch (use --force-with-lease, and only on your own branch)
- resolving conflicts blindly
Say it like this
A common question: walk me through how you add a new test to the suite. Say: I pull main and create a feature branch, write the test, and check it fails when the bug is present and passes when it is not. I commit small changes with clear messages, push, and open a pull request explaining what, why and the proof. CI must be green and a teammate reviews it before merge. Secrets and build output never go into Git.
- "I pull main, create a feature
- branch, write the test and see it fail with the bug and pass without, commit small
- changes with clear messages, push and open a PR with what, why and proof. CI must be green and a teammate reviews
- it. Secrets stay out of Git."