Git & GitHub– Assignment– 2

Basic Questions

  1. Create a repo core-repo, add a file a.txt, write text in it, and check repo status.
  2. Edit a.txt, without staging, show the difference between working directory and last commit.
  3. Stage a.txt after editing, and show the difference between staged and last commit.
  4. Add a new file b.txt but do not stage it. Run git status and capture the output.
  5. Delete file b.txt from the repo and check status.
  6. Stage the deletion of b.txt and commit it.
  7. Create a .gitignore file and ignore all .log files. Show repo status after adding debug.log.
  8. Add a folder temp/ and ignore it using .gitignore. Show status after adding temp/test.txt.
  9. Edit a.txt, stage it, then undo the staging (unstage it). Which command will you use?
  10. Restore the previous version of a.txt before staging. Show the command.
  11. Make a wrong commit with message “wrng msg”, then change the last commit message to “correct msg”.
  12. Commit a file, then use git revert to undo that commit.
  13. Create a new branch feature-x.
  14. Switch to feature-x branch using git checkout.
  15. Switch back to main branch using git switch.
  16. Create a file feature.txt in feature-x branch and commit it.
  17. Merge branch feature-x into main (fast-forward).
  18. Create another branch feature-y, add a file, commit, then merge into main.
  19. Delete the branch feature-x locally.
  20. Create a remote branch test-remote, push it, then delete it using command.

 Intermediate Questions

  1. Create a repo, add 2 files, commit them, edit both, and run git diff before staging.
  2. Stage one file, keep the other unstaged, and run git diff –staged.
  3. Add 3 commits, then reset the last commit (soft reset). Show commit history.
  4. Reset the same commit again (hard reset). What’s the difference?
  5. Commit a file, then delete it locally, and use git restore to bring it back.
  6. Add 2 commits, then use git revert on the first one. Show logs.
  7. Create branch login, add commits, then switch back to main.
  8. Merge login into main and check if it was fast-forward or 3-way merge.
  9. Create 2 branches from main (devA and devB), add different changes in the same file, then merge both into main to generate a conflict.
  10. Show the conflict markers inside the file.
  11. Resolve the conflict manually and commit.
  12. Create branch bugfix, commit changes, then delete it before merging. Show logs.
  13. Create and switch to a branch in a single command.
  14. Add 3 files, ignore 1 of them using .gitignore, and show status.
  15. Demonstrate restoring only staged changes while keeping unstaged ones.
  16. Create a repo, commit, then undo the last commit without losing changes.
  17. Use git diff branch1 branch2 to compare two branches.
  18. Commit a file, change it, commit again, then run git log –stat.
  19. Create branch test, push it to remote, then delete it from local.
  20. Stage 2 files, unstage only 1 file without affecting the other.

 Advanced Questions

  1. Create a repo merge-demo, add 3 commits in main, create branch exp, add 2 commits, then merge exp into main (non-fast-forward). Show logs.
  2. Generate a merge conflict by editing the same line in main and exp, then merge. Show the conflict output.
  3. Resolve the merge conflict using command line (git add + commit).
  4. Demonstrate how to abort a merge in progress.
  5. Add 5 commits, then use git reset –hard HEAD~3. Show commit history.
  6. Create branch hotfix, commit changes, merge into main, then delete hotfix both locally and remotely.
  7. Revert multiple commits at once using commit ranges.
  8. Create .gitignore to ignore .env, add it, check status, then force add .env ignoring rule with -f.
  9. Show how to restore a deleted file from 2 commits ago.
  10. Create repo → add file → commit → branch → modify file in branch → merge → resolve conflict → delete branch. Show full command sequence.