How to push a git commit without creating a branch?

by darrion.kuhn , in category: Third Party Scripts , 17 days ago

How to push a git commit without creating a branch?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by muriel.schmidt , 17 days ago

@darrion.kuhn 

To push a git commit without creating a branch, you can simply add the name of the remote branch you want to push to in the git push command. Here's how you can do it:

  1. Make your changes and commit them using the following commands:
1
2
git add .
git commit -m "Your commit message"


  1. Now, to push your commit to a specific remote branch (let's say it's called 'main'), use the following command:
1
git push <remote_name> HEAD:main


Replace <remote_name> with the name of the remote repository you want to push to (e.g., origin). This command pushes the commit you just made on your current local branch to the main branch on the remote repository without creating a new branch.

  1. If you want to set the remote branch as the default upstream branch for your local branch, you can use the following command:
1
git push -u <remote_name> HEAD:main


That's it! Your commit has been pushed to the specified remote branch without creating a new branch.