K2xL
K2xL

Reputation: 10330

Don't allow pulling of specific remote while on specific local branch

In git, I have a branch called localbranch1 and i do a git pull origin remotebranch1

I have another local branch called localbranch2 which should be pulling from remotebranch2

I have a habbit of doing a git pull origin remotebranch1 accidently when I'm on localbranch2 which cause merges that I don't want to make happen.

Is there a way to "lock" or restrict myself from pulling from a different branch? It would be great if I got some type of error or warning when trying to pull from a different remote branch. Or should I approaching this workflow in a completely different way?

Upvotes: 0

Views: 44

Answers (2)

vergenzt
vergenzt

Reputation: 10427

If each of the mentioned local branches always corresponds to the same branch on origin, the easiest solution is to set up the branches to track the remote branch, and then simply use git pull origin:

$ git branch --set-upstream localbranch1 origin/remotebranch1
Branch localbranch1 set up to track remote branch remotebranch1 from origin.
  ...
$ git pull

Upvotes: 1

twalberg
twalberg

Reputation: 62519

I don't think there's any way to restrict this short of wrapping it in an "Are you sure you want to..." confirmation script. What would probably be best would be to make sure things are set up so that, no matter which branch you're on, a bare git pull does what you want it to, then break yourself of the habit of typing any more than git pull (or git pull origin if you have multiple remotes). Reserve git pull <remote> <branch> for unusual non-standard workflow events.

Upvotes: 0

Related Questions