我有一个非空目录(例如/etc/something),其中的文件不能被重命名、移动或删除。 我想检查这个目录到git到位。 我希望能够使用“git push”或类似的东西将这个存储库的状态推送到远程存储库(在另一台机器上)。

这是微不足道的使用Subversion(目前我们使用Subversion)使用:

svn mkdir <url> -m <msg>
cd <localdir>
svn co <url> .
svn add <files etc>
svn commit -m <msg>

git等价于什么?

我可以“git克隆”到一个空目录,并简单地移动.git目录,一切工作吗?


当前回答

下面是我的解决方案,如果您使用一些默认的自述文件或许可证创建存储库

git init
git add -A
git commit -m "initial commit"   
git remote add origin https://<git-userName>@github.com/xyz.git //Add your username so it will avoid asking username each time before you push your code
git fetch
git pull https://github.com/xyz.git <branch>
git push origin <branch> 

其他回答

做这件事的最简单的方法,我发现有用的是下面。

这可能不是官方的方法,但效果很好。

假设您的PC上有一个名为“XYZ”的项目。 现在你想在github上制作这个项目的git repo并使用它的功能。

第一步:登陆“www.github.com”

步骤2:使用“README”创建存储库。Md”文件(按你喜欢的名字命名)

步骤3:克隆存储库到您的PC。

第四步:在克隆文件夹中你会得到两个东西:"。文件夹和一个README。md”文件。复制这两个到你的项目文件夹“XYZ”。

步骤5:删除克隆的repo。

第六步:添加、提交和推送项目的所有文件和文件夹。

现在,您可以使用项目“XYZ”作为git存储库。

这是2021年新的官方做法。导航到包含文件的目录。这假设存储库中没有文件。

git init
git add .
git commit -m "initial commit"   
git remote add origin https://<git-userName>@github.com/xyz.gi
git branch -M main    # New
git push -u origin main # New

有时我必须使用这个命令来设置上游。

git branch --set-upstream-to=origin/main main

然后用这个命令强制push。

git push -u origin main --force

下面是我的解决方案,如果您使用一些默认的自述文件或许可证创建存储库

git init
git add -A
git commit -m "initial commit"   
git remote add origin https://<git-userName>@github.com/xyz.git //Add your username so it will avoid asking username each time before you push your code
git fetch
git pull https://github.com/xyz.git <branch>
git push origin <branch> 

假设你已经在<url>和一个空仓库上设置了一个git守护进程:

cd <localdir>
git init
git add .
git commit -m 'message'
git remote add origin <url>
git push -u origin main

我也遇到过类似的问题。我创建了一个新的存储库,不在我想要创建存储库的目录中。然后,我将创建的文件复制到我想要创建存储库的目录。然后使用刚才将文件复制到的目录打开现有存储库。

注意:我确实使用github桌面来制作和打开现有的存储库。