问题
I want to be able to make backups of my project in a windows environment without having to manually copy and paste my whole folder. Unfortunately I am not allowed to use a remote git server for this project, so I was wondering if I could use git for backing up my project on a mounted hard drive.
I have tried this solution:
git remote add Y file:///path/to/Y
However, when I try to push I receive this error:
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I tried to init a bare repository on my mounted device and local directory but I faced the same error.
Summarizing, I want to be able to backup my project in a windows environment automatically or with few commands such as git commit and git push. Any ideas?
回答1:
Here is what I did and what as far as I know works:
First you create a git repo:
cd e:/tmp
mkdir backup
cd backup
git --bare init
Now the git repository was created you need to go to your files.
Let's say you use xampp and you want a backup from one of your projects.
cd e:/xampp/htdocs/project
git init
git add .
git remote add backup e:/tmp/backup
git commit -m "First commit"
git push backup master
Boom now it saved everything into your backup into master branch ;) You can even do it in different HDs... that's how I keep code tracked at home 4 free into my backup HD.
Hope this help someone else in future as well.
See ya! ;)
回答2:
you are almost right, just remove the "file:" in your route:
git remote add Y /path/to/Y
and everything should work fine. If it doesnt work you should try this workaround,
enter this inside your removable hard disk drive:
git clone /path/to/your/project
then whenever you want to make a backup just enter a git pull inside your removable hard drive project folder. Any of this solutions should work for you
来源:https://stackoverflow.com/questions/42722240/how-do-i-use-git-without-having-a-proper-git-server