Branching, history and collaboration workflow.
8 items at beginner level · all topics
You accidentally committed a .env file containing API keys. What do you do?
Rotate the credentials first. That's the only step that actually makes you safe, since the secret is already in every clone, fork and CI cache that pulled before you noticed. Cleaning up Git history is a second, separate job that comes after.
Your branch is 5 commits behind main and you have uncommitted changes. How do you update safely?
Save the uncommitted work first with a stash or a WIP commit, then fetch and rebase onto origin/main, then bring it back. The real point is knowing what git pull would do to your branch before you run it.
A developer says they pulled the latest code but their branch doesn't match the remote. How do you investigate?
It's almost always a tracking problem, not corruption. They pulled a different branch than they think, or their branch tracks something other than what they assume. `git branch -vv` and `git log HEAD..origin/main` usually answer it in two commands.
Code works on the developer's machine but fails in Jenkins. How could Git be involved?
Stop guessing about the code and compare commit SHAs first. CI often builds a different commit than the developer tested: a merge commit, a stale workspace, a shallow clone, missing submodules, or a file that's gitignored locally but needed at build time. Only once the SHAs match is it worth looking at the code.
You made a commit but forgot to include one file, and it isn't pushed yet. What do you do?
Stage the file and run `git commit --amend`. Amend doesn't edit the previous commit, it replaces it with a new one that has a new SHA, which is free while the commit is still local and a problem the moment someone else has it.
A developer started a feature branch from an outdated main. How would you fix it?
Fetch, then rebase the branch onto origin/main so the work replays on current code. Rebase is right while the branch is private; if it's been pushed and others use it, merge main in instead so you don't rewrite shared SHAs.
A Git repository has become huge and cloning takes 20 minutes. What would you investigate?
Measure before you guess. Find the biggest objects in history, because size usually comes from binaries and build artifacts committed long ago. Deleting them today does nothing: the old blobs stay in history until you rewrite it or route developers around downloading them in the first place.
What is the difference between git fetch and git pull?
Fetch downloads remote commits and updates your remote-tracking branches, but never touches your working tree. Pull is fetch plus merge or rebase, so it changes your branch. Fetch is the safer move when you're debugging or scripting.