Git

Why “git push origin master” Does Not Work

On Git, first users work on the local machine and then push the changes to the centralized server for updating other project members. To push the content of the local repository into the remote repository, users first need to set the remote URL with the desired remote name which can be performed by utilizing the “git remote add” command.

This post will briefly discuss the “git push origin master” command.

Why “git push origin master” Does Not Work?

Sometimes, Git users get a fatal error while pushing the local content into the GitHub server because the remote URL is not specified. To add it, the “git remote add <remote-name> <remote-url>” command can be used.

In the below-provided steps, first, we will demonstrate how the “fatal:….” error encounters and then resolve it.

Step 1: Switch to Git Repository

Initially, type out the “cd” command and navigate to the Git local repository:

$ cd "C:\Users\LENOVO\Git\test-repo"

Step 2: Generate File

To create a new file in the repository, run the “touch” command:

$ touch file1.txt

Step 3: Push File to Git Index

Then, execute the “git add” command to add a file into the staging index:

$ git add file1.txt

Step 4: Commit Changes

Next, update the repository by committing all added changes through the “git commit” command:

$ git commit -m "file1.txt added"

Step 5: Push Local Content

Execute the provided command and specify the remote and branch name:

$ git push origin master

As you can see, the above command gives a “fatal: ‘origin’ does not…….” error after executing it:

Note: Check out the following steps to resolve the above-listed error.

Step 6: Check Remote URL List

Then, check the remote URL list by utilizing the given command:

$ git remote -v

According to the below-provided output, the remote URL is not specified that we previously used for pushing the local content:

Step 7: Add Remote URL

Add the remote URL to the list by running the following command:

$ git remote add origin https://github.com/GitUser0422/demo.git

Step 8: Push Local Changes

Finally, execute the “git push” command to push the local repository data into the centralized server:

$ git push origin master

As you can see, we have successfully pushed the local content into the remote repository:

That’s all about resolving the “git push origin master” command not working issue.

Conclusion

The “git remote origin master” does not work when the remote URL is not specified. To resolve this issue, use the “git remote add <remote-name> <remote-url>” command. Then, run the “git push <remote-name> <branch>” command to push the local content. This post described the issues that occur while executing the “git push origin master” does not work.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.