[英]How to properly initialize a remote git repository
I have a local git server running on my NAS and I'm developing on my laptop and workstation, all in my local network.我有一个本地 git 服务器在我的 NAS 上运行,我正在我的笔记本电脑和工作站上进行开发,所有这些都在我的本地网络中。 So, if I want to start a project in a new empty repo, I'm following this answer and所以,如果我想在一个新的空仓库中开始一个项目,我会关注这个答案并且
cd ${PROJECT}.git; git init --bare
在 NAS cd ${PROJECT}.git; git init --bare
上创建一个裸仓库“mynewproject.git” cd ${PROJECT}.git; git init --bare
cd ${PROJECT}.git; git init --bare
cd ${PROJECT}; git init
创建一个空的“repo”“mynewproject”,也在 NAS cd ${PROJECT}; git init
cd ${PROJECT}; git init
git add . ; git commit -m "initial commit" -a
在“newproject” git add . ; git commit -m "initial commit" -a
进行初始提交git add . ; git commit -m "initial commit" -a
git add . ; git commit -m "initial commit" -a
git remote add origin ssh://${USER}@${REMOTEIP}${PROJECT}.git
使裸git remote add origin ssh://${USER}@${REMOTEIP}${PROJECT}.git
成为当前文件夹的远程源git remote add origin ssh://${USER}@${REMOTEIP}${PROJECT}.git
git push origin master
推送到主git push origin master
rm -rf $PROJECT
删除“项目”目录rm -rf $PROJECT
And then I can clone the ${PROJECT}.git
repo from other machines.然后我可以从其他机器克隆${PROJECT}.git
库。 This whole process seems overly complicated.这整个过程似乎过于复杂。 I mean, I scripted it,我的意思是,我编写了它,
HOSTIP=XXX.XXX.XXX.XXX
USER=YYYYY
PROJECT=$1
[[ -z "${PROJECT}" ]] && exit 1
PROJECTNAME=${PROJECT}
PROJECT=$(pwd)/${PROJECT}
# create project and .git folders
mkdir ${PROJECT}
mkdir ${PROJECT}.git
# initialize folders for git
cd ${PROJECT}.git
git init --bare
cd ${PROJECT}
git init
# create initial project directory
echo "#!/bin/bash" > ${PROJECT}/ENV_${PROJECTNAME}.sh
git add .
git commit -m "initial commit" -a
# 'link' to 'remote' .git folder
git remote add origin ssh://${USER}@${HOSTIP}${PROJECT}.git
# push to master
git push origin master
# delete 'project' directory
rm -rf $PROJECT
echo "CREATED PROJECT $PROJECT.git"
echo "Clone with git clone ssh://${USER}@${HOSTIP}${PROJECT}"
exit 0
but still, is this the right way to go about this?但是,这是解决这个问题的正确方法吗?
Your process is mostly good but a bit overcomplcated.你的过程大多是好的,但有点过于复杂。 You don't need a non-bare repository on the NAS, so your workflow should be您不需要 NAS 上的非裸存储库,因此您的工作流程应该是
cd ${PROJECT}.git; git init --bare
在 NAS 上创建一个裸仓库: cd ${PROJECT}.git; git init --bare
cd ${PROJECT}.git; git init --bare
. cd ${PROJECT}.git; git init --bare
。${PROJECT}.git
repo on another machine.在另一台机器上克隆${PROJECT}.git
库。 This adds the remote to the non-bare repo.这会将遥控器添加到非裸存储库中。cd ${PROJECT}; git init; git remote add origin ssh://${USER}@${HOSTIP}${PROJECT}.git
您可以在另一台机器上创建一个空的非裸仓库,而不是克隆,并添加 remote: cd ${PROJECT}; git init; git remote add origin ssh://${USER}@${HOSTIP}${PROJECT}.git
cd ${PROJECT}; git init; git remote add origin ssh://${USER}@${HOSTIP}${PROJECT}.git
cd ${PROJECT}; git init; git remote add origin ssh://${USER}@${HOSTIP}${PROJECT}.git
. cd ${PROJECT}; git init; git remote add origin ssh://${USER}@${HOSTIP}${PROJECT}.git
。git add . ; git commit -m "initial commit" -a
在另一台机器上克隆的非裸存储库中进行初始提交: git add . ; git commit -m "initial commit" -a
git add . ; git commit -m "initial commit" -a
git add . ; git commit -m "initial commit" -a
. git add . ; git commit -m "initial commit" -a
。git push origin master
.将 master 从另一台机器推送到 NAS 上的裸仓库: git push origin master
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.