From 7082775f0e2d8198984105c193105136237b25ea Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 14 May 2021 16:38:31 -0500 Subject: [PATCH] Add Push To A Branch On Another Remote as a git til --- README.md | 3 +- git/push-to-a-branch-on-another-remote.md | 36 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 git/push-to-a-branch-on-another-remote.md diff --git a/README.md b/README.md index 545f522..59101ba 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_1123 TILs and counting..._ +_1124 TILs and counting..._ --- @@ -268,6 +268,7 @@ _1123 TILs and counting..._ - [Move The Latest Commit To A New Branch](git/move-the-latest-commit-to-a-new-branch.md) - [Pick Specific Changes To Stash](git/pick-specific-changes-to-stash.md) - [Pulling In Changes During An Interactive Rebase](git/pulling-in-changes-during-an-interactive-rebase.md) +- [Push To A Branch On Another Remote](git/push-to-a-branch-on-another-remote.md) - [Quicker Commit Fixes With The Fixup Flag](git/quicker-commit-fixes-with-the-fixup-flag.md) - [Rebase Commits With An Arbitrary Command](git/rebase-commits-with-an-arbitrary-command.md) - [Reference A Commit Via Commit Message Pattern Matching](git/reference-a-commit-via-commit-message-pattern-matching.md) diff --git a/git/push-to-a-branch-on-another-remote.md b/git/push-to-a-branch-on-another-remote.md new file mode 100644 index 0000000..7385ca1 --- /dev/null +++ b/git/push-to-a-branch-on-another-remote.md @@ -0,0 +1,36 @@ +# Push To A Branch On Another Remote + +The kind of `git-push` I do most often is: + +```bash +$ git push origin HEAD +``` + +which I have aliased to `put` in my `.gitconfig`. + +`HEAD` generally refers to whatever branch you currently have checked out. So +this command will take the state of your current branch and push it to the +branch of the same name on the `origin`, which is a _remote_ (see `git remote +-v`). + +If you have other remotes set up, such as a `staging`, `heroku`, etc., then you +may instead want to push to one of those. + +```bash +$ git push heroku HEAD +``` + +This will push the state of the current branch to that branch on the `heroku` +remote. + +If I instead want to push the changes from one local branch to a different +named remote branch, then I have to specify both like so: + +```bash +$ git push heroku staging:main +``` + +This will push the state of my local `staging` branch to the `main` branch on +the `heroku` remote. + +[source](https://devconnected.com/how-to-push-git-branch-to-remote/)