From: Junio C Hamano Date: Mon, 06 Nov 2023 23:38:48 GMT Subject: Re: git refusing to merge branches when pulling using a refspec Message-ID: In-Reply-To: Santiago García Pimentel writes: > Hello, > > I'm dealing with a small automation (CI) to synchronise some specific branches between two git repositories. > > I need to sync a branch with other using a user-given refspec. e.g. > > $ git pull origin "refs/heads/branchOrigin:refs/heads/branchDestination”. > > (I’ll have a list of refspecs, but so far Im trying to make it work with one) > > When the branch can be fast-forwarded there is no problem, but I cannot manage to make it work when it cant. > > I just. get the message "[rejected] branchOrigin -> branchDestination (non-fast forward)." With the "pull" command above, you are doing two logically independent things. Do you really need to do both? * git pull "" ":" first does a "git fetch" to locally update with the commit that is pointed at by at the repository. * then, into the currently checked out HEAD, the taken from is merged into. If you do not need to update locally, don't give : part on the command line. If you do need to update locally and safely, then thank that you got the [rejected] message. Because the was updated at the side that is not based on what you have at locally, you may be losint commits from your local if you let the first stage of the "git pull" go through, and that is what the failing command is about. If you do need to update locally but you do not have anything valuable on locally (in other words, is used only to keep track of at , and if rewinds the history of their and loses some commits, you want to lose these commits the same way from your ), then add "+" before the refspec, i.e. git pull "" "+:"