From 775b7685f6063596e3932fee735ff0fc51a98936 Mon Sep 17 00:00:00 2001 From: Alex Ball Date: Mon, 14 Jul 2025 11:19:22 +0100 Subject: [PATCH 1/2] Add challenge around "git push" Closes #166. This lesson has few challenges, so this issue seemed like a good opportunity to add one. --- episodes/03-sharing.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/episodes/03-sharing.md b/episodes/03-sharing.md index 9e69fa0a..97ca2204 100644 --- a/episodes/03-sharing.md +++ b/episodes/03-sharing.md @@ -394,6 +394,36 @@ To https://github.com//hello-world And let's check on GitHub that we now have 2 commits there. +::::::::::::::::::::::::::::::::: challenge + +## Challenge: Two different push commands + +The first time we pushed our changes, we used a longer command: + +```bash +$ git push -u origin main +``` + +The second time, we used a shorter command: + +```bash +$ git push +``` + +Why didn't we use the same command both times? + +::::::::::::::::: solution + +The first time, Git didn't know where to push the changes, so we had to tell it the destination to use. +We also used the `-u` flag to tell Git to remember that decision. + +The second time, Git knew a destination it could use, so we didn't specify one; +not only did we save on typing, we also avoided worries about typing the wrong destination. + +:::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::::: + ## Pulling changes When working with others, or when we're making our own changes from different machines, we need a way of pulling those From 6f82b9f00e564a91b2937415e827610599ba1a54 Mon Sep 17 00:00:00 2001 From: Alex Ball Date: Thu, 14 Aug 2025 09:16:21 +0100 Subject: [PATCH 2/2] Provide more detailed explanation of upstream Incorporates wording from @srerickson. Thank you! --- episodes/03-sharing.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/episodes/03-sharing.md b/episodes/03-sharing.md index 97ca2204..7ef27c83 100644 --- a/episodes/03-sharing.md +++ b/episodes/03-sharing.md @@ -414,11 +414,14 @@ Why didn't we use the same command both times? ::::::::::::::::: solution -The first time, Git didn't know where to push the changes, so we had to tell it the destination to use. -We also used the `-u` flag to tell Git to remember that decision. - -The second time, Git knew a destination it could use, so we didn't specify one; -not only did we save on typing, we also avoided worries about typing the wrong destination. +Branches can be configured with an "upstream" branch (a branch on a remote repository), +which is used automatically for `push` and `pull` operations. + +The `main` branch's upstream wasn't set when we created it. +The `-u` (or `--set-upstream`) flag tells `git push` which remote branch to use; +it also sets the remote branch as the local branch's upstream. +Once we've set it, we don't need to specify the remote branch in future `push` and `pull` operations. +This saves on typing and means we won't `push` to or `pull` from the wrong remote branch. ::::::::::::::::::::::::::