Reputation: 14375
I have a particular project that I never want to push to GitHub. That is, I only want to use locally with Git and make sure it is never pushed to a remote repository. Is there a way to mark a directory/project so that it is locked down and the push command will fail if tried? That way I don't have to worry about accidentally pushing it. I've been using Git for so long doing add/commit/push is rooted in my fingers and I don't want to have an accident during some late night programming session.
Upvotes: 0
Views: 655
Reputation: 3581
You can add a local remote as follows :
1) Create a bare repository somewhere in your machine using the following:
git init --bare path/to/localrem.git
This will create a bare repository without a working directory, this is what's typically used in actual remotes. (it'll create a folder called localrem.git
which is the usual .git repo but this is for remotes, well obviously you can change localrem
for any name you like)
2) Next in your original repository you add the new remote, as you would add any ordinary remote, except the path isn't a url :
git remote add origin path/to/localrem.git
3) Now you can push as you see fit without having to worry about the world seeing your work.
git push origin master
Of course that depends on which branch you would like to keep in your local remote.
Upvotes: 3
Reputation: 147
Two choices (that I know of):
1) Remove the local repository's reference to the remote repository.
git remote remove origin
Typically, there is only one remote reference that is named 'origin'. You can check for addiitonal references:
git remote show
2) Keep the references, but point them to different repositories:
git remote set-url origin ${somethingElse}
Upvotes: 4
Reputation: 410662
You can add a pre-push
hook to prevent the repository from being pushed. Rename the existing .git/hooks/pre-push.sample
to .git/hooks/pre-push
(or create that file if it does not exist). The contents of the file should be something like this:
#!/bin/sh
echo 'Repository cannot be pushed' 2>&1
exit 1
The echo
is optional but the script should exit non-0.
Upvotes: 5