Interview Q&A / Git & GitHub
Git & GitHub interview questions
Branching, merge vs rebase, resolving conflicts and pull requests, the way teams actually work.
Prefer rapid revision? Practise Git & GitHub short interview answers →
- Can you resolve a merge conflict on GitHub without using the command line?
Yes for simple text conflicts. The pull request page has a Resolve conflicts button that opens an editor with markers; fix them, mark resolved and commit. Complex cases like deleted or binary files need a local merge.
BeginnerQuick answer1 min read - Does git stash save untracked files, and how do you include them?
By default git stash saves only tracked changes. Add -u (--include-untracked) to also stash new files, or -a to include ignored files as well.
BeginnerQuick answer1 min read - How big should a commit be?
One logical change that builds and passes tests on its own. Small, focused commits are easier to review, revert, cherry-pick and bisect than a giant commit mixing several unrelated things.
BeginnerQuick answer1 min read - How can a team reduce merge conflicts?
Keep branches short-lived, pull or rebase from main often, make small focused pull requests, avoid reformatting whole files, and talk when two people touch the same area.
BeginnerQuick answer1 min read - How do the patterns in a .gitignore file work?
Each line is a pattern. * matches any characters except a slash, a trailing slash matches directories, ** matches nested directories, ! negates a pattern, and
BeginnerQuick answer1 min read - How do you cancel a merge that went wrong?
Run git merge --abort. It restores your branch and working tree to the state before the merge started. It works while the merge is still unresolved and uncommitted.
BeginnerQuick answer1 min read - How do you change the message or contents of your last commit?
Use git commit --amend. It replaces the last commit with a new one, letting you edit the message and include newly staged changes. Because it rewrites history, avoid it on commits you have already pushed and shared.
BeginnerQuick answer1 min read - How do you delete a branch locally and on the remote?
Delete it locally with git branch -d name (or -D to force), and delete it on the remote with git push origin --delete name. They are separate; removing one does not remove the other.
BeginnerQuick answer1 min read - How do you find which branches are already merged into main?
Run git branch --merged main to list branches whose commits are all in main, and git branch --no-merged main for the rest. Merged ones are usually safe to delete.
BeginnerQuick answer1 min read - How do you link a pull request to an issue so that it closes automatically?
Write a closing keyword such as Closes
BeginnerQuick answer1 min read - How do you list, name and inspect your stashes?
Save with git stash push -m 'message' so each stash has a label, list them with git stash list, and see their contents with git stash show -p stash@{n}.
BeginnerQuick answer1 min read - How do you rename a Git branch, including one already pushed?
Locally use git branch -m old new. For a pushed branch, push the new name, set its upstream, and delete the old name on the remote. Tell teammates, since their copies still track the old name.
BeginnerQuick answer1 min read - How do you tag a commit that is not the latest one?
Give the commit hash after the tag name, for example git tag -a v1.0 3f9c2ab -m 'Release 1.0'. Without a hash, Git tags the current HEAD.
BeginnerQuick answer1 min read - How do you undo a commit that you already pushed to a shared branch?
Use git revert, which adds a new commit that cancels the bad one. History is not rewritten, so teammates can pull normally. Avoid reset plus force-push on shared branches.
BeginnerQuick answer1 min read - How do you undo the last commit but keep your changes?
Run git reset --soft HEAD~1 to keep the changes staged, or git reset HEAD~1 to keep them unstaged. The commit disappears from the branch while your work stays in the files.
BeginnerQuick answer1 min read - How do you unstage a file you added by mistake?
Use git restore --staged file, or the older git reset HEAD file. The file leaves the staging area but your edits stay in the working directory.
BeginnerQuick answer1 min read - How do you view Git history in a compact, readable way?
Use git log --oneline for one line per commit, adding --graph --decorate --all to see branches and merges drawn as a tree. Options like -n, --author and --since filter the output.
BeginnerQuick answer1 min read - What are the three ways to merge a pull request on GitHub?
Create a merge commit keeps all commits plus a merge commit. Squash and merge combines them into one commit. Rebase and merge replays the commits onto main without a merge commit, giving linear history.
BeginnerQuick answer1 min read - What do the <<<<<<<, ======= and >>>>>>> markers in a file mean?
They are Git's conflict markers. The part between <<<<<<< and ======= is your current branch's version, and the part between ======= and >>>>>>> is the incoming version. You edit the file to the final text and delete all three marker lines.
BeginnerQuick answer1 min read - What do you need before you can use git bisect?
A known bad commit, a known good commit earlier in history, and a way to test the bug at each step, either by hand or with a script. A clean working tree also helps.
BeginnerQuick answer1 min read - What does 'Your branch is ahead of origin/main by 2 commits' mean?
You have two local commits that are not on the remote yet. Nothing is wrong. Run git push to publish them. If it says behind, the remote has commits you do not have yet.
BeginnerQuick answer1 min read - What does git cherry-pick do?
cherry-pick copies the changes of one chosen commit onto your current branch as a new commit. It lets you take a single fix without merging the whole branch it lives on.
BeginnerQuick answer1 min read - What does git status tell you, and how do you read its output?
git status reports your current branch, how it compares with its upstream, and three groups of files: staged changes ready to commit, modified but unstaged changes, and untracked files Git does not know yet.
BeginnerQuick answer1 min read - What is a commit hash, and why is it such a long string?
A commit hash is a SHA-1 fingerprint of the commit's contents, author, message and parent. It uniquely identifies the commit and changes if anything inside it changes. You can usually use just the first 7 characters.
BeginnerQuick answer1 min read - What is a draft pull request, and when would you use one?
A draft PR signals that work is in progress and cannot be merged yet. It lets you share code early, run CI, and get feedback, then you click Ready for review when it is done.
BeginnerQuick answer1 min read - What is a fast-forward merge, and when does Git use it?
A fast-forward merge happens when the target branch has no new commits of its own, so Git just moves its pointer forward to the other branch's tip. No merge commit is created and history stays a straight line.
BeginnerQuick answer1 min read - What is a merge commit, and how is it different from a normal commit?
A merge commit has two (or more) parents instead of one. It records the point where two lines of history were joined, and holds the combined result of both branches.
BeginnerQuick answer1 min read - What is an upstream branch in Git?
An upstream branch is the remote branch that your local branch is linked to. With it set, plain git pull, git push and git status know where to send and compare changes without extra arguments.
BeginnerQuick answer1 min read - What is branch protection on GitHub, and what rules can you set?
Branch protection rules guard important branches like main. You can require pull requests, a number of approvals, passing status checks, up-to-date branches, and block force pushes and deletion.
BeginnerQuick answer1 min read - What is GitHub Actions?
GitHub Actions is GitHub's built-in automation. A workflow, written in a YAML file under .github/workflows, runs jobs on GitHub-hosted machines when events like a push or pull request occur, commonly for tests, builds and deployment.
BeginnerQuick answer1 min read