From e9b8dd8a81e756060fd53e7baab4aa4f0ee7cfdf Mon Sep 17 00:00:00 2001 From: Rob Moss Date: Wed, 28 Feb 2024 20:48:08 +1100 Subject: [PATCH] Add branch names to "git push -u remote" commands The default setting for `push.default` requires the user to configure an upstream branch with the same name as the local branch in order for `git push -u remote` to push the local branch upstream. --- docs/collaborating/sharing-a-branch.md | 2 +- docs/using-git/how-to-use-branches.md | 2 +- docs/using-git/pushing-and-pulling-commits.md | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/collaborating/sharing-a-branch.md b/docs/collaborating/sharing-a-branch.md index 7773940b..f9ffd251 100644 --- a/docs/collaborating/sharing-a-branch.md +++ b/docs/collaborating/sharing-a-branch.md @@ -20,7 +20,7 @@ Remember that you can merge commits from their branch into your own branches at 2. Push this branch to your remote repository: ```sh - git push -u origin + git push -u origin collab/jamie ``` 3. Your collaborator can then make a local copy of this branch: diff --git a/docs/using-git/how-to-use-branches.md b/docs/using-git/how-to-use-branches.md index 783ccb59..1ea861b9 100644 --- a/docs/using-git/how-to-use-branches.md +++ b/docs/using-git/how-to-use-branches.md @@ -35,7 +35,7 @@ git checkout -b my-new-branch my-other-branch # From an existing branch You can then create a corresponding **upstream branch** in your remote repository (in this example, called "origin") by running: ```sh -git push -u origin +git push -u origin my-new-branch ``` ## Working on a remote branch diff --git a/docs/using-git/pushing-and-pulling-commits.md b/docs/using-git/pushing-and-pulling-commits.md index 68127d2a..63a0d470 100644 --- a/docs/using-git/pushing-and-pulling-commits.md +++ b/docs/using-git/pushing-and-pulling-commits.md @@ -29,7 +29,14 @@ This requires that you have **created at least one commit** in your local reposi Once you have at least one commit in your local repository, you can create a corresponding **upstream branch** in the remote repository with the following command: ```sh -git push -u origin +git push -u origin +``` + +The default branch will probably be called `"main"` or `"master"`, depending on your [Git settings](first-time-git-setup.md). +You can identify the branch name by running: + +```sh +git branch ``` !!! note @@ -50,7 +57,7 @@ and pull commits by running: git pull ``` -without having to specify the remote repository. +without having to specify the remote repository or branch name. ## Forcing updates to a remote repository