Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure git to avoid accidental git push

Tags:

git

After git clone, the config in the new repo looks like:

remote.origin.url=<some url> remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/master 

Then, I can execute "git pull" and "git push". But I'm interested in only do "git pull", because I want to push into another repo.

One thing I can do is:

git add remote repo-for-push <some other url> git push repo-for-push master 

But I would like to configure git to use default and distinct repositories for pull and push, i.e:

git pull # pulls from origin git push # pushes into repo-for-push, avoiding accidental push into the origin 

How can this be configured? Thanks in advance.

EDIT:
Basically, I want to setup the default push repo to be different from the default fetch/pull repo.

like image 517
Daniel Fanjul Avatar asked Feb 09 '09 11:02

Daniel Fanjul


People also ask

What would you use to prevent force pushes git?

If you have the appropriate permissions on your "central" git repository, you can disable force push by git config --system receive. denyNonFastForwards true .

How do I restrict direct push to master?

To find it go to Settings > Branches > Branch Protection Rules and click 'Add Rule'. Then, enter the name of the branch you want to protect and click the checkbox to require pull request reviews before merging. By default, this only stops people who are not moderators.

Should I always git pull before push?

It's important to fetch and pull before you push. Fetching checks if there are any remote commits that you should incorporate into your local changes. If you see any, pull first to prevent any upstream merge conflicts.


1 Answers

Looks like

git config remote.origin.receivepack /bin/false 

Makes push to remote origin fail.

like image 140
iny Avatar answered Sep 23 '22 00:09

iny