How to push a git commit without creating a branch?

by darrion.kuhn , in category: Third Party Scripts , 7 months ago

How to push a git commit without creating a branch?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by muriel.schmidt , 7 months 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.

Related Threads:

How to commit without message in git?
How to rebase without intermediate commit on git?
How to push to a specific branch on bitbucket using git?
How to configure remote upstream without `git push`?
How to branch from deleted branch in git?
How do i push to my github repo without cloning it again?