Reputation: 902
Sometimes I type accidentaly the wrong branch name, when I do "git pull origin BRANCH".
Is there a way to forbid "git pull origin XXX" when XXX is not the same branch I have currently checked on my local repository? i.e. allow "git pull" only if the local-checked branch is XXX and not YYY.
That is, I do want "merge" to hapen, but only if I pull the same branch I have currently checked in my local repository. Is there a way I can configurate the local repository to allow "git pull" only from the same branch-name?
For example:
Case 1:
Current checked branch on local repository is "test"
[* test ] /code$ git pull origin master
This merges the code from "test"-branch to my local "master" branch. ==> I want to forbid this.
Case 2:
Current checked branch on local repository is "master"
[* master ] /code$ git pull origin master
This merges the changes from remote "master" branch to my local "master" branch. ==> This is ok.
I hope I explained my problem well.
Thanks in advance.
Upvotes: 1
Views: 5275
Reputation: 578
From 'man git-pull':
git pull runs git fetch with the given parameters and calls git merge to
merge the retrieved branch heads into the current branch.
Thus,
git fetch origin master
does not do an automatic merge.
You can also do:
git fetch origin master:tmp
to create a new branch 'tmp' from the fetched master branch.
Then git merge FETCH_HEAD
will show you any conflicts.
Upvotes: 1
Reputation: 40982
You should use git fetch
which does the following:
Fetches all the objects from the remote repository that are not present in the local one.
EDIT:
What is the difference between 'git pull' and 'git fetch'? ("git pull does a git fetch followed by a git merge"
)
EDIT 2:
AFAIK you can't forbid to pull into a branch since it can be locally name and be whatever whenever.
But you can change the project to the very last commit before the pull by using
git pull --abort
didn't check it should be something like this.
One more thing you can do is git checkout
to the SHA1 of the branch before the you made the git pull
.
Remember you can always undo all by (irreversible):
git clean -fd
git reset HEAD --hard
Upvotes: 3
Reputation: 11791
Don't worry too much, you can undo the mess by a judicious use of git reset
. Just make sure that each time you pull your repository is in shipshape.
Upvotes: 1
Reputation: 94429
Use git fetch
which does not merge the code. git pull
is actually a combination of two commands git fetch
followed by git merge
Upvotes: 1