@@ -174,15 +174,22 @@ func checkoutLocalBranch(config *config.GitXargsConfig, ref *plumbing.Reference,
174
174
checkoutErr := worktree .Checkout (co )
175
175
176
176
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" )
181
187
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 )
184
190
185
- return branchName , errors .WithStackTrace (checkoutErr )
191
+ return branchName , errors .WithStackTrace (checkoutErr )
192
+ }
186
193
}
187
194
188
195
// 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,
212
219
return branchName , nil
213
220
}
214
221
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
+
215
227
// Track the error pulling the latest from the remote branch
216
228
config .Stats .TrackSingle (stats .BranchRemotePullFailed , remoteRepository )
217
229
0 commit comments