Skip to content

Commit 16a41d4

Browse files
authored
Merge pull request #182 from alex-ball/patch-166
Add challenge around "git push"
2 parents dbb4605 + 6f82b9f commit 16a41d4

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

episodes/03-sharing.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,39 @@ To https://github.com/<your_github_username>/hello-world
394394

395395
And let's check on GitHub that we now have 2 commits there.
396396

397+
::::::::::::::::::::::::::::::::: challenge
398+
399+
## Challenge: Two different push commands
400+
401+
The first time we pushed our changes, we used a longer command:
402+
403+
```bash
404+
$ git push -u origin main
405+
```
406+
407+
The second time, we used a shorter command:
408+
409+
```bash
410+
$ git push
411+
```
412+
413+
Why didn't we use the same command both times?
414+
415+
::::::::::::::::: solution
416+
417+
Branches can be configured with an "upstream" branch (a branch on a remote repository),
418+
which is used automatically for `push` and `pull` operations.
419+
420+
The `main` branch's upstream wasn't set when we created it.
421+
The `-u` (or `--set-upstream`) flag tells `git push` which remote branch to use;
422+
it also sets the remote branch as the local branch's upstream.
423+
Once we've set it, we don't need to specify the remote branch in future `push` and `pull` operations.
424+
This saves on typing and means we won't `push` to or `pull` from the wrong remote branch.
425+
426+
::::::::::::::::::::::::::
427+
428+
:::::::::::::::::::::::::::::::::::::::::::
429+
397430
## Pulling changes
398431

399432
When working with others, or when we're making our own changes from different machines, we need a way of pulling those

0 commit comments

Comments
 (0)