将本地副本推送到Git远程存储库。

huangapple go评论53阅读模式
英文:

push to git remote repo using a local copy

问题

给定一个我可以访问的现有私有远程仓库,其中只包含一个 README.md 文件和一个 .gitignore 文件。我们将这个仓库称为 "myRepo"。

在我的本地机器上,我创建了一个名为 "myRepo" 的文件夹,添加了一些文件,并希望将所有内容推送到远程的 "myRepo"。

我知道有 git init 命令。我可能需要执行 git remote add "url_to_myRepo",对吗?

而且,我的本地文件夹包含很多我不想被 git 跟踪的文件。我是否需要在执行 git init 之前创建一个 .gitignore 文件,还是可以在之后创建?

英文:

Given an existing private remote repository, to which I have access to, which contains only a README.md and a .gitingore file. Lets call this repo "myRepo".

Locally on my machine, I created a folder "myRepo", added some files to it and want to push everything to the remote "myRepo".

I am aware of the git init command. I would probably have to do git remote add "url_to_myRepo" then. Is this the right way to go?

And, my local folder contains a whole bunch of files which I do not want to be tracked by git. Do I have to create a .gitignore file before I do git init, or can I do it also afterwards?

答案1

得分: 2

运行 git init 只是创建一个本地存储库目录。然后,如 @jim-redmond 建议的那样,您应该运行 git remote add origin $URL,然后运行 git pull 以使您的本地存储库与远程同步。
然后,您需要运行 git add 命令来添加文件。您可以使用该命令明确地添加单个文件,但如果要添加目录,最好先创建 .gitignore 文件。然后,当然,您需要运行 git commit 将文件实际保存到存储库中。然后,您可以运行 git push 将提交的文件保存到远程存储库。

英文:

Running git init just creates a local repository directory. Then as @jim-redmond advised you should run git remote add origin $URL, then git pull to get your local repository synced with the remote.
Then, you then need to git add files. You can add individual files explicitly with that command, but if you are going to add directories, you should probably have the .gitignore file created first. Then of course you need to git commit to have the files actually saved into the repository. Then you can run git push to save your committed files to the remote repository.

答案2

得分: 0

你需要执行git remote add origin <url_of_the_repo>,然后你可以使用git push origin将本地更改推送到远程仓库。

如果你不想跟踪本地文件夹中的某些文件,请在.gitignore中列出它们。这样,Git将忽略它们,不会提醒你有未提交的更改。

编辑:在使用git add / git commit命令之前,你需要先提交你的更改。

英文:

You need to do git remote add origin &lt;url_of_the_repo&gt;, and then you can do git push origin to push local changes to the remote repo.

If you don't want to track certain files in your local folder, list them in .gitignore. This way, git will ignore them and won't bother you that you have uncommitted changes.

EDIT: You need to commit your changes first using the git add / git commit commands.

huangapple
  • 本文由 发表于 2023年7月28日 04:31:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76783216.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定