Branching, merge vs rebase, conflicts, history recovery, code review
Practise these as flashcards. One or two lines each; the ones you miss come back first.
Start freeA Git commit is a snapshot of your project's files at a specific point in time. It records changes and includes a message describing what was changed.
You can create and switch to a new branch with git checkout -b branch-name. This creates the branch and moves HEAD to it.
HEAD is a pointer to the current branch and commit you have checked out. It's where new commits will be added.
You use git fetch origin to update your local tracking branches with changes from the remote repository.
I use merge when integrating shared branches, like merging a feature branch into main, to preserve history. I use rebase for local feature branches to keep history linear and avoid unnecessary merge commits, but only when the branch hasn’t been shared.
When Git marks a conflict, I open the affected files, look for the conflict markers, and manually edit the code to resolve the differences. After resolving, I stage the changes and complete the merge with git commit.
Trunk-based development uses a single main branch with short-lived feature branches. It encourages frequent integration, reduces merge conflicts, and speeds up delivery by keeping everyone close to the latest code.
git reset moves HEAD and can change your working directory and index, potentially removing commits. git revert creates a new commit that undoes the changes from a previous commit, which is safer for shared history.
I would use git reflog to find the commit hash and then use git checkout or git cherry-pick to restore it to my branch.
Git stash temporarily saves changes that aren’t ready to commit, so you can switch branches or work on something else without losing your progress. You can later apply the stashed changes with git stash pop.
I use git cherry-pick <commit-hash> to apply a specific commit from another branch onto my current branch.
I start with git bisect start, mark the current commit as bad, and a known good commit. Git checks out commits between them, and I test each one, marking them as good or bad. Git narrows down the commit that introduced the regression.