检查后,我如何上传我的项目的Git存储库到GitHub?,我仍然不知道如何让一个项目上传到我的GitHub存储库。

我创建了一个存储库,并想将我的项目上传到它。

我在存储库页面上查看了某种上传按钮,但我没有看到任何类似的东西。

到目前为止,我已经查看了提供的链接,但仍然一无所获。他们提到了命令行;是Windows命令行还是Git Bash?因为我不能让他们做任何事。

我也尝试使用Git GUI,但是当我选择我想要的文件夹时,它说它不是Git存储库…需要拉上拉链吗?我尝试在文件夹中添加.gitconfig文件,但没有什么不同。


当前回答

GitHub发布了一个本地Windows客户端,使以下所有步骤变得多余。

您还可以使用Sourcetree在Windows上获得Git和Mercurial的设置。


下面是你在Windows下的操作方法:

If you don't have Git installed, see this article on how to set it up. Open up a Windows command prompt. Change into the directory where your source code is located in the command prompt. First, create a new repository in this directory git init. This will say "Initialized empty git repository in ....git" (... is the path). Now you need to tell Git about your files by adding them to your repository. Do this with git add filename. If you want to add all your files, you can do git add . Now that you have added your files and made your changes, you need to commit your changes so Git can track them. Type git commit -m "adding files". -m lets you add the commit message in line.

到目前为止,即使你不使用GitHub,上面的步骤也是你要做的。它们是启动Git存储库的正常步骤。请记住,Git是分布式的(去中心化的),这意味着使用Git不需要“中央服务器”(甚至不需要网络连接)。

现在,您希望将更改推到GitHub托管的Git存储库中。你可以通过告诉Git添加一个远程位置来做到这一点,你可以用下面的命令来做到:

Git远程添加origin https://github.com/yourusername/your-repo-name.git

*注意:在你做git远程添加origin之前,你应该在GitHub中创建your-repo-name…

完成此操作后,Git现在就知道远程存储库了。然后你可以让它推送(也就是“上传”)你提交的文件:

Git push -u origin master

其他回答

在这里我解释一下我是如何在Windows上做到这一点的。

确保安装了Git和GitHub。

安装完成后,打开Git Bash。

这样就会弹出一个如下图所示的窗口:

继续,输入cd ~以确保您在主目录中。您可以通过输入pwd来检查您所在的地址;

现在你需要创建一个GitHub账户。创建一个GitHub帐户后,继续并登录。

登录后,在右上角点击+,选择“New Repository”

然后在打开的窗口中,在“repository name”框中键入您希望拥有的存储库名称。如果你喜欢,添加“描述(可选)”,并标记“用README初始化这个存储库”。然后点击“创建存储库”。

现在去你的C盘;创建新文件夹git。现在转到“Git Bash”窗口;将目录更改为c驱动器,输入CD ~;cd / c。 如果你在那里输入ls,它会显示那里的文件夹。确保它显示了Git文件夹:

现在回到浏览器;转到你的GitHub页面,点击你制作的存储库,点击“克隆或下载”,并复制显示在那里的地址(通过选择复制到剪贴板)。

现在回到Git Bash。使用cd git命令进入git文件夹;现在写以下命令连接到你的GitHub(输入用户名和密码时,它要求你):

git config --global user.name "Your Name"

然后是:git config——global user。电子邮件youremail@domain.com。

下一种类型:git克隆(URL),而不是(URL),键入你从你的GitHub页面复制的GitHub存储库的地址;(例如,git clone https://github.com/isalirezag/Test.git)。

现在如果你执行ls命令,你会看到你的存储库。如果你也打开窗口中的Git文件夹,你会看到你的存储库被添加为一个文件夹。

现在使用cd命令转到存储库:cd Test

继续,复制和粘贴任何文件,您想放在这个存储库在该文件夹。

为了将文件传输到您的存储库,您现在需要做以下工作:

git型

添加文件名(filename是你想要上传的文件名),或者如果你想添加文件夹中的所有文件,你可以输入下面的命令:

转到添加 。

然后输入:git commit -m "adding files"。然后:git push -u origin master。

然后你就万事俱备了。如果你刷新你的GitHub帐户,文件应该在那里:)

确保系统上安装了Git。我正在用windows操作系统解释这个过程[尽管它不应该是依赖于操作系统的工作]

以下是我的做法:

Open the cmd (you can do with git bash as well if you've installed git bash). Go to your project directory (where your project is located, it's essentially changing to directory either usiing cd path or through manual folder navigation). Now type git init. This will initialize an empty repository if it is first time and Enter. For example: git init Now type git add <filename>(if specific file) or git add <filename1> <filename2> <filenameN> (if specific but more than one files) or git add . (if you want to add all files) and enter. Now type git commit -m "commit message goes here" and enter. (in case if you need to check the status you can do by typing git status) and enter. Now type git remote add origin git_repository_url (check git remote -v go check remote repository) and Enter. Now it's turn to push it to the remote repository [essentially taking all the changes from local git to cloud(github) ...git push origin master and enter (if you get error you push it forcefully by typing ...git push -f origin master and enter.

注意:master是你的主分支的名称。如果您有多个分支,请确保选择相应的分支名称。

现在,您已经完成了将它从本地计算机添加到远程存储库的工作。刷新它,它将出现在您创建的存储库的选定分支中。

简单的步骤:git拉源master或main会给出一个致命错误:

无法找到远程参考主机

下面的步骤就可以了。

git init Git添加。 Git commit -m "初始提交" Git远程添加origin https://github.com/yourusername/your-repo-name.git git分支-M main Git push -u origin main

上传项目到Git的步骤:

步骤1 -打开cmd并将当前工作目录更改为您的项目位置。

步骤2 -将项目目录初始化为Git存储库。

git init

步骤3 -在本地存储库中添加文件。

add .

步骤4 -提交您在本地存储库中暂存的文件。

git commit -m "First commit"

步骤5 -复制远程存储库URL。

步骤6 -在本地位置中添加远程存储库URL作为源。

git add origin copied_remote_repository_url

步骤7 -确认您的来源是否更新。

git remote show origin

第8步-推更改到您的GitHub存储库

git push origin master.

为了将一个新项目上传到Git中(首先你需要有项目的本地代码库和上传项目的Git存储库。在Git中,你需要有你的凭证)。

List item Open Git Bash Go to the directory where you have the code base (project location) cd to project location cd ////** Then here you need to execute Git commands. git init Press Enter then you will see something like this below. The initialized empty Git repository in ://****/***/.git/, so git init will initialize the empty Git repository at local git add . Press Enter The above command will add all the directories, subdirectories, files, etc. You will see something like this: warning: LF will be replaced by CRLF in **************. The file will have its original line endings in your working directory. git commit -m "first commit" Press Enter. -m provided option for adding comment. It will commit the code to the stage environment. You will see some thing like this: [master (root-commit) 34a28f6] adding ******** warning: LF will be replaced by CRLF in c*******. The file will have its original line endings in your working directory. 27 files changed, 3724 insertions(+) create mode 100644 ***** create mode 100644 ***** create mode 100644 ***** git remote add origin http://username@git:repopath.git Press Enter. This will add to the repository. git push -u origin master Press Enter. This will upload all from local to repository in this step you need to enter password for the repository where you will be uploading the code. You will see some thing like this below: Counting objects: 33, done. Delta compression using up to 12 threads. Compressing objects: 100% (32/32), done. Writing objects: 100% (33/33), 20.10 KiB | 0 bytes/s, done. Total 33 (delta 14), reused 0 (delta 0) To http://username@git:repolocation.git \ [new branch] master -> master Branch master set up to track remote branch master from origin.