Git & GitHub– Assignment– 2
Basic Questions
- Create a repo core-repo, add a file a.txt, write text in it, and check repo status.
- Edit a.txt, without staging, show the difference between working directory and last commit.
- Stage a.txt after editing, and show the difference between staged and last commit.
- Add a new file b.txt but do not stage it. Run git status and capture the output.
- Delete file b.txt from the repo and check status.
- Stage the deletion of b.txt and commit it.
- Create a .gitignore file and ignore all .log files. Show repo status after adding debug.log.
- Add a folder temp/ and ignore it using .gitignore. Show status after adding temp/test.txt.
- Edit a.txt, stage it, then undo the staging (unstage it). Which command will you use?
- Restore the previous version of a.txt before staging. Show the command.
- Make a wrong commit with message “wrng msg”, then change the last commit message to “correct msg”.
- Commit a file, then use git revert to undo that commit.
- Create a new branch feature-x.
- Switch to feature-x branch using git checkout.
- Switch back to main branch using git switch.
- Create a file feature.txt in feature-x branch and commit it.
- Merge branch feature-x into main (fast-forward).
- Create another branch feature-y, add a file, commit, then merge into main.
- Delete the branch feature-x locally.
- Create a remote branch test-remote, push it, then delete it using command.
Intermediate Questions
- Create a repo, add 2 files, commit them, edit both, and run git diff before staging.
- Stage one file, keep the other unstaged, and run git diff –staged.
- Add 3 commits, then reset the last commit (soft reset). Show commit history.
- Reset the same commit again (hard reset). What’s the difference?
- Commit a file, then delete it locally, and use git restore to bring it back.
- Add 2 commits, then use git revert on the first one. Show logs.
- Create branch login, add commits, then switch back to main.
- Merge login into main and check if it was fast-forward or 3-way merge.
- Create 2 branches from main (devA and devB), add different changes in the same file, then merge both into main to generate a conflict.
- Show the conflict markers inside the file.
- Resolve the conflict manually and commit.
- Create branch bugfix, commit changes, then delete it before merging. Show logs.
- Create and switch to a branch in a single command.
- Add 3 files, ignore 1 of them using .gitignore, and show status.
- Demonstrate restoring only staged changes while keeping unstaged ones.
- Create a repo, commit, then undo the last commit without losing changes.
- Use git diff branch1 branch2 to compare two branches.
- Commit a file, change it, commit again, then run git log –stat.
- Create branch test, push it to remote, then delete it from local.
- Stage 2 files, unstage only 1 file without affecting the other.
Advanced Questions
- 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.
- Generate a merge conflict by editing the same line in main and exp, then merge. Show the conflict output.
- Resolve the merge conflict using command line (git add + commit).
- Demonstrate how to abort a merge in progress.
- Add 5 commits, then use git reset –hard HEAD~3. Show commit history.
- Create branch hotfix, commit changes, merge into main, then delete hotfix both locally and remotely.
- Revert multiple commits at once using commit ranges.
- Create .gitignore to ignore .env, add it, check status, then force add .env ignoring rule with -f.
- Show how to restore a deleted file from 2 commits ago.
- Create repo → add file → commit → branch → modify file in branch → merge → resolve conflict → delete branch. Show full command sequence.