AI Hints
Home›Git & GitHub Tutorial›Project: Rescue Mission
Git & GitHub · Lesson 126 of 144

Project: Finishing the Rescue

Branch, push, restore.

⏱ 2 min read▶ Video at 2:17:29🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

Last problem. The shop commit is on main, but our team only allows changes through pull requests. Let's move it to a branch, push it, and bring back our unfinished work.

Project: Finishing the Rescue
From the video: Project: Finishing the Rescue
  • The shop commit is on main
  • It belongs on a branch
  • Then restore our work

Move, push, restore

Git branch shop labels the commit. Reset main back to origin main, where GitHub has it. Switch to shop, and push it, ready for a pull request. Back on main, git stash pop brings back the blog post. Every problem is solved.

git
git branch shop
git reset --hard origin/main
HEAD is now at f63a17a Link to about page
git switch shop
Switched to branch 'shop'
git push -u origin shop
To https://github.com/sam/my-site.git
 * [new branch]      shop -> shop
branch 'shop' set up to track 'origin/shop'.
git switch main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
git stash pop
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   index.html

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .env

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (f9d409a87d48c6260c500cf9ac350e9302889cf1)

The final check

One last look. The graph shows main matching GitHub, and the clean shop commit on its own branch. Status shows our unfinished blog post, and dot ENV as untracked. That's because the new ignore rule lives on the shop branch, until it's merged. Until then, just be careful not to add it. And l s shows the secret is still safely on disk, where it belongs.

git
git log --oneline --graph --all -n 3
* 373488f (origin/shop, shop) Add shop page
* f63a17a (HEAD -> main, origin/main) Link to about page
* ef9c947 Add basic styles
git status --short
 M index.html
?? .env
ls -a
.
..
.env
.git
about.html
index.html
style.css

Summary

You investigated, stashed, removed a secret, moved a commit, and restored your work. That's a real rescue. Next, a real open source contribution, from start to finish.

Key takeaways
  • Investigate first
  • Fix one problem at a time
  • Check the result
Next up: Project: Finding Something to Fix — your first open source issue