I am using git and I am doing my development work, which I don't want to push, even by mistake. Is there a method to disable push in certain local repository. One method is to rename the branch, another is to undo push if one does it by mistake, but I hope there should be a more direct method.
2 Answers
The following command will let pulls work, but pushes will try to use the URL no_push
and fail:
git remote set-url --push origin no_push
-
8
-
16@user984260: I guess you could set the remote for just that branch:
git config branch.<branch-name>.remote no_push
. But if the branch is a local development branch, with its own name, is it really a problem? It won't be pushed by default (git push
with no arguments by default pushes only branches which exist both locally and on the remote) and even if you do push it, you're just creating a new branch on the remote which you can promptly delete.– CascabelApr 21, 2012 at 16:51 -
Whatever you do, use
git config -l
to verify/get a better understanding. (If it isn't there, it didn't happen ;-) ). Even better structured, usecat .git/config
Mar 12, 2017 at 7:14 -
3Thanx! If you have an upstream repo in addition to origin then you can do the following to make sure you can't push to upstream:
git remote set-url --push upstream no_push
. Check the effect withgit remote -v
before and after the change.– WladJan 27, 2020 at 16:02 -
1@OZZIE you can use the same
git set-url
command to allow pushes again - it'll be something likegit set-url --push origin git@github.com:my-user/my-repo.git
. If you issue agit config --list
it's likely that the original setting is there asremote.origin.url=<the thing you want>
Feb 23 at 10:28
Depending on the remote, you may be able to reset its URL to use the read-only Git protocol instead of SSH or HTTPS. E.g., for a project on GitHub, do
git remote set-url <remote> git://github.com/Team/Project.git
where <remote>
is commonly origin
. git remote -v
will give you a list of remotes; those that start with https
or have the form <user>@<host>:<path>
usually allow pushing.
-
-
1@YassineElBadaoui you probably need to add
--push
afterset-url
to just modify for pushing. But this more recent answer makes the intent clearer when you come back to this in future, I think.– SamOct 22, 2019 at 12:25