@@ -174,15 +174,22 @@ func checkoutLocalBranch(config *config.GitXargsConfig, ref *plumbing.Reference,
174174 checkoutErr := worktree .Checkout (co )
175175
176176 if checkoutErr != nil {
177- logger .WithFields (logrus.Fields {
178- "Error" : checkoutErr ,
179- "Repo" : remoteRepository .GetName (),
180- }).Debug ("Error creating new branch" )
177+ if config .SkipPullRequests &&
178+ remoteRepository .GetDefaultBranch () == config .BranchName &&
179+ strings .Contains (checkoutErr .Error (), "already exists" ) {
180+ // User has requested pull requess be skipped, meaning they want their commits pushed on their target branch
181+ // If the target branch is also the repo's default branch and therefore already exists, we don't have an error
182+ } else {
183+ logger .WithFields (logrus.Fields {
184+ "Error" : checkoutErr ,
185+ "Repo" : remoteRepository .GetName (),
186+ }).Debug ("Error creating new branch" )
181187
182- // Track the error checking out the branch
183- config .Stats .TrackSingle (stats .BranchCheckoutFailed , remoteRepository )
188+ // Track the error checking out the branch
189+ config .Stats .TrackSingle (stats .BranchCheckoutFailed , remoteRepository )
184190
185- return branchName , errors .WithStackTrace (checkoutErr )
191+ return branchName , errors .WithStackTrace (checkoutErr )
192+ }
186193 }
187194
188195 // Pull latest code from remote branch if it exists to avoid fast-forwarding errors
@@ -212,6 +219,11 @@ func checkoutLocalBranch(config *config.GitXargsConfig, ref *plumbing.Reference,
212219 return branchName , nil
213220 }
214221
222+ if pullErr == git .NoErrAlreadyUpToDate {
223+ // The local branch is already up to date, which is not a fatal error
224+ return branchName , nil
225+ }
226+
215227 // Track the error pulling the latest from the remote branch
216228 config .Stats .TrackSingle (stats .BranchRemotePullFailed , remoteRepository )
217229
0 commit comments