英文:
How do I create a New Public GitHub Repository and push my locally stored, newly created code to my GitHub account?
问题
我有一个存储在硬盘上的文件夹。其中包含了我想要放入一个新的公共GitHub存储库的文件。我应该使用什么顺序的终端命令来完成这个任务?
我搜索了一下。尝试了提供的说明,以将本地托管的代码添加到GitHub,说明在这里提供:https://docs.github.com/en/migrations/importing-source-code/using-the-command-line-to-import-source-code/adding-locally-hosted-code-to-github
英文:
I have a folder on my hard drive. It contains files that I would like to have in a New, Public GitHub Repository. What sequence of terminal commands would I use to accomplish this?
Googled it. Tried the provided instructions to add locally hosted code to GitHub provided here: https://docs.github.com/en/migrations/importing-source-code/using-the-command-line-to-import-source-code/adding-locally-hosted-code-to-github
答案1
得分: 1
GitHub非常擅长引导你完成这个过程。
这分为两个阶段。首先,你要创建一个新的GitHub仓库。然后,将你现有的文件添加到该仓库中。
- 通过访问https://github.com/[用户名]?tab=repositories 并点击右上角的绿色"New"按钮来创建一个新的GitHub仓库。
- 填写你的新仓库的详细信息,然后点击右下角的绿色"Create repository"按钮。
当你创建一个新仓库时,GitHub会提供一系列不同方式将文件添加到仓库中的说明。你需要的部分叫做**...或者从命令行推送现有仓库**。
但首先,我们需要确保本地有一个git
仓库。你说你有一些文件的目录,但听起来它们并不在git
仓库中。所以请按照以下步骤进行操作(如果你已经有了本地的git
仓库,那么可以忽略这些步骤):
- 打开一个命令行窗口并进入包含你的文件的目录。
- 初始化一个空的本地
git
仓库 -git init
- 将你的文件添加到本地
git
仓库中 -git add .
- 提交你的文件 -
git commit -m 'Initial commit'
现在你有了一个空的GitHub仓库和一个包含你文件的本地git
仓库。下一步(也是最后一步)是通过按照GitHub仓库网页上的说明将它们连接在一起。这些说明可能类似于以下内容:
git remote add origin git@github.com:[用户名]/[仓库名].git
git branch -M main
git push -u origin main
如果现在刷新你的GitHub仓库的网页,你会看到设置说明已被替换为你的文件。
英文:
GitHub is very good at guiding you through this.
This is done in two stages. First, you create a new Github repo. Then you add your existing files to that repo.
- Create a new GitHub repo by visiting https://github.com/[username]?tab=repositories and pressing the green "New" button in the top right corner.
- Fill in the details of your new repo and press the green "Create repository" button in the bottom right corner.
When you create a new repo, GitHub presents you with a list of instructions on how to get files into that repo in a number of different ways. The section you want is called …or push an existing repository from the command line
But first we need to ensure we have a local git
repo. You say you have a directory of files, but it sounds like they aren't in a git
repo. So follow these instructions (if you do already have a local git
, then you can ignore these lines):
- Open a command line window and go to the directory containing your files.
- Initialise an empty local
git
repo -git init
- Add your files to the local
git repo
-git add .
- Commit your files -
git commit -m 'Initial commit
Now you have an empty GitHub repo and a local git
repo with your files in it. The next (and final step) is to link the two together by following the instructions on the GitHub repo's web page. They will be something like this:
git remote add origin git@github.com:[username]/[reponame].git
git branch -M main
git push -u origin main
If you now refresh the web page for your GitHub repo, you'll see the setup instructions have been replaced with your files.
答案2
得分: 0
Prerequisites:-
Follow the steps below:
- 打开命令行并导航到要上传到GitHub的文件夹。
- 使用以下命令在文件夹内初始化git:
git init
- 使用以下命令将文件添加到暂存区:
git add .
- 现在,使用以下命令提交文件:
git commit -m "你的消息"
- 现在前往Github新建仓库,输入你的仓库名称,确保不选中“添加 README.md”选项,参考此处 。
- 点击创建仓库。
- 现在会打开一个如下的新页面
- 现在复制代码以推送现有仓库,并将其粘贴到本地终端中。
- 按回车键,完成(注意:第一次使用GitHub时,需要在终端上进行身份验证)。
- 你的代码已推送。
英文:
Prerequisites:-
- Github account. Github
- Git installed and configured on the system(recommended). Download git
Follow the steps below:
- Open the command line and navigate to the folder you want to upload to Git Hub.
- Initialize git inside the folder, with the command:
git init
- Add the files to the staging area with the command:
git add .
- Now, commit the files with the command:
git commit -m "your message"
- Now go to Github new repo, and enter the name of your repository, make sure you don't check the add README.md option, see this .
- Click on Create repository.
- Now a new page as below will open
- Now copy the code to push an existing repository, and paste them in your local terminal.
- Press enter and done(note: you have to authenticate your terminal the first time with Git Hub).
- Your code is pushed.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论