我有一个文件夹,里面有我的项目资料。我怎么能把这个项目推到Github的存储库?

我尝试了以下步骤:

我在GitHub上创建了空仓库。 我运行git-bash并输入git init,所以在根项目中出现了。git文件夹。 我使用git add sourcesFolderName添加了一些文件到版本控制中 我使用git commit -m "initial commit"来提交上一步添加的文件 我指定远程存储库使用git远程添加MyProject <url> 最后git推送,但什么都没有推送到远程repo…(未授权失败)

那么我怎么能把现有的资源推到新创建的github回购?


当前回答

我知道,这是一个老问题,但我试图解释每一步,所以它可以帮助别人。这是我如何添加一个现有的源代码到git:

Create the repo on the git, so you'll have the ssh || https where you're gonna remote add you source code. In your terminal go to the path of your project. Run git init (here you initiate the project as a git one). Run git add * (here you add all the files and folders from you project). Run git commit -m "Initial Commit." (here you commit your files and folders added in step #4; keep in mention that you can't push your changes without committing them). Run git remote add origin https://your_username@bitbucket.org/your_username/project-name.git (here you add a remote project where your source it's gonna be pushed; replace my link with your ssh || https from the step #1). Run git push -u origin master (here you push your source into the git repository).

注意:这些都是将源代码推入主分支的简单步骤。

其他回答

这个对我来说很有用(需要的时候留作参考)

# Go into your existing directory and run below commands
cd docker-spring-boot
echo "# docker-spring-boot" >> README.md
git init
git add -A
git commit -m "first commit"
git branch -M master
git remote add origin https://github.com/devopsmaster/docker-spring-boot.git
git push -u origin master
                

你需要在推送时指定哪个分支和哪个远程:

➤ git init ./
➤ git add Readme.md
➤ git commit -m "Initial Commit"
➤ git remote add github <project url>
➤ git push github master

将按预期工作。

默认情况下,你可以这样做:

➤ git branch -u github/master master

这将允许您在不指定远程或分支的情况下从master执行git推送。

首先,用你的项目名在Github上创建一个新的存储库。然后按照以下步骤。

1)git init
2)git add *
3)git commit -m "first commit"
4)git remote add origin https://github.com/yuvraj777/GDriveDemo.git
5)git push -u origin master

如果您的存储库中已经有. Git /文件夹,则Git init不会初始化。所以,就你的情况来说,做

(1) rm -rf .git/

2)滚英寸

(3) git远程添加origin https://repository.remote.url

(4) git commit -m“提交信息”

(5) git push -f origin master

截至2019年7月29日,Github向用户提供了在创建回购时完成这项任务的说明,并提供了几个选项:

在命令行上创建一个新的存储库

git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/user/repo.git
git push -u origin master

从命令行推送现有存储库

git remote add origin https://github.com/user/repo.git
git push -u origin master

从其他存储库导入代码

按导入按钮初始化进程。

对于视觉学习者来说: