Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I mark a GIT remote as read only? [duplicate]

Tags:

git

github

I have read/write access to a repo on GitHub. I have a local clone of that repo. I'd like to be able to pull changes from that remote, but I should never push changes to it.

Is there a way I can mark the remote as read-only so I never accidentally type in the wrong command and push to it?

like image 730
Marc Hughes Avatar asked Apr 22 '12 17:04

Marc Hughes


People also ask

How do I copy a remote branch?

If you have a single remote repository, then you can omit all arguments. just need to run git fetch , which will retrieve all branches and updates, and after that, run git checkout <branch> which will create a local copy of the branch because all branches are already loaded in your system.

Does git clone add remote?

git remote add just creates an entry in your git config that specifies a name for a particular URL. You must have an existing git repo to use this. git clone creates a new git repository by copying an existing one located at the URI you specify.

Can you have two git remotes?

You can add multiple remotes by using git remote or git config commands or editing the config file. As git can group multiple remotes, you can follow any of the following ways to configure multiple remotes to push simultaneously(no need all). You can set multiple remote URLs to a single remote using git remote.


2 Answers

You could shut off default pushes via

git config push.default nothing 

or for stronger protection on a specific remote you could break pushes to that remote entirely by e.g.

git config remote.origin.pushurl "you really didn't want to do that" 
like image 79
jthill Avatar answered Oct 11 '22 12:10

jthill


git remote set-url origin --push "hey, stop pushing" 

Note that the following removes an explicitly configured push URL, but then pushes will use the fetch URL, so not what you want:

git remote set-url origin --delete --push ".*" 
like image 41
yoyo Avatar answered Oct 11 '22 12:10

yoyo