| by Arround The Web | No comments

Fix Git’s “fatal: no upstream branch” Error Quickly Example

On Git, developers work on branches, and it is the most valuable feature of Git, which enables programmers to test in the remote development environment that no one else can view unless the branch explicitly collaborates with others. However, when a programmer creates and pushes a new branch to their remote repository, they often face the “fatal: no upstream branch” error.

This study will elaborate

So, let’s start!

When “fatal: no upstream branch” Error Occurs?

The above-stated error occurs when the user creates a new branch and pushes it to the Git remote repository. To give you a better idea, we will first display the error and then provide the solution to resolve it.

Let’s move on and check out the procedure!

Step 1: Move to Git Local Directory

Execute the below command and move to the specified Git directory:

$ cd "C:\Users\nazma\Git\Demo10"

Step 2: Clone Remote Directory

Next, clone the remote directory on Git local repository using the “git clone” command:

$ git clone https://github.com/GitUser0422/first_demo.git

Step 3: Create and Switch Branch

Then, run the following command to create and switch immediately to the newly created branch:

$ git switch -c my-branch

Step 4: Git Push

To push the newly created branch to a remote repository, execute the “git push” branch with the remote name:

$ git push origin

As a result, you will get the following fatal error:

Now, move ahead to the solution to the above-displayed error.

Example: Fix Git’s “fatal: no upstream branch” Error Quickly

To fix the “fatal: no upstream branch” error, execute the provided “git push” command with your branch name:

$ git push --set-upstream origin my-branch

Adding the “–set-upstream” option in the above-given command will set the remote as upstream directory and fix the previously encountered error:

That’s all! We have effectively provided the solution to fix the “fatal: no upstream branch” error.

Conclusion

Most of the time, developers encounter the “fatal: no upstream branch” error while pushing the newly created branch to the Git remote repository. To resolve this issue, the “$ git push –set-upstream origin <branch-name>” command is utilized to push the branch and set remote as upstream. This study demonstrated when the mentioned error occurs and how to fix it.

Share Button

Source: linuxhint.com

Leave a Reply