git says everything-up-to-date when pushing changes to a remote branch
Asked Answered
D

2

10

i have commits that are in a remote repository (origin/master) which i want to put in a branch created from that repository (origin/remote_branch).

when i checkout to that remote branch

git checkout -b mybranch origin/remote_branch

then cherry-picked the commits that i made

git cherry-pick 9df63616b0428cf6edc4261adb533a1ac516b9a0

git says everything-up-to-date when i try to push.

git push

is there anything i'm doing wrong?

Darby answered 8/9, 2009 at 2:49 Comment(0)
J
24

Depending on your version of Git, it may be trying to push branches with matching names, i.e., master to origin/master and remote_branch to origin/remote_branch. If your origin repository doesn't have a branch named mybranch then it thinks there's nothing to update.

To override this default, you can explicitly tell git which branch to use as the source (mybranch) and which to use as the destination on the remote repository (remote_branch):

git push origin mybranch:remote_branch

There's a config option to tell git to push to remote tracking branches by default:

git config --global push.default tracking

I find this more intuitive and I think it's the behavior you're looking for. Checkout the push.default option in the git config man page. Also checkout the Examples section in the git push man page to see how to override the default behavior.

Jimenez answered 8/9, 2009 at 3:17 Comment(1)
whoa! "If your origin repository doesn't have a branch named mybranch then it thinks there's nothing to update." this totally did it! thanks for the quick reply! :)Darby
F
0

With a recent (2019+) version of Git, creating a branch would be done with git switch (more precise than the confusing git checkout)

git switch -c mybranch --track origin/remote_branch

That way, mybranch is automatically linked to origin/remote_branch, and a simple git push will be enough to push new mybranch commits to origin/remote_branch.

Faircloth answered 31/12, 2019 at 17:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.