Git

How to Change the Git remote ‘push to’ Default

When Git users want to push the local machine changes to the GitHub server, they need to specify the branch name each time while doing so, and it becomes difficult for developers. Users need to set the “push.default” as a “current” in the Git config file to make it more efficient, which will push local changes from the current working local branch to a similar remote repository branch.

This study will discuss the method of changing the Git remote “push to” default.

How to Change the Git remote ‘push to’ Default?

In order to modify the setting of the Git remote “push to” default value, check out the following procedure:

    • Switch to the Git local repository.
    • Add the value of the “push.default” as a “current” in the Git config file.
    • Verify the modified Git config file.
    • Generate and switch to the new branch.
    • Execute the “git push -u” command without specifying a specific branch name.

Step 1: Redirect to the Git Repository

At first, execute the “cd” command with the required local repository path and switch to it:

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

 
Step 2: Modify Git Config File

Now, to modify the Git configuration file through the “git config” command:

$ git config --global push.default current

 
In the above-stated command:

    • push.default” is used to change the Git remote default value.
    • current” value represents the current working branch that will be settled as default.
    • –global” flag is used to configure these settings in Git.

 

Next, verify the previously modified default value of the “push.default” is added or not:

$ git config --global push.default

 
It can be seen that the default remote is changed into the “current” successfully:


Step 3: Create and Switch to New Branch

After that, generate the new branch and immediately switch to it with the help of the “git checkout” command:

$ git checkout -b new-branch

 
Here, the “-b” option represents the branch, and the “new-branch” is the name of the new local branch:


Step 4: Git Push With Default Git Remote Branch

Finally, execute the “git push” command to push the current working branch without specifying it:

$ git push -u

 
Here, the “-u” flag is used to set the current working branch as a tracking branch through upstream operations:


That’s it! We have provided the easiest way to change Git remote “push to” default.

Conclusion

To change the Git remote from “push to” default, first, move to the Git local repository and modify the value of the “push.default” as a “current” in the Git config file. Then, verify the modified Git config file. Next, generate and switch to the new branch. Lastly, run the “git push -u” command without specifying a specific branch name. This study described the method to change the Git remote “push to” default.

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.