我如何从我的计算机导入源代码到我的GitHub帐户?


是的。创建一个新的存储库,在源代码当前存在的目录中执行git init。

更多信息请点击:http://help.github.com/creating-a-repo/


这在优秀的免费电子书ProGit中得到了解释。它假设您已经有一个本地Git存储库和一个远程Git存储库。连接它们使用:

$ git remote
origin
$ git remote add pb git://github.com/paulboone/ticgit.git
$ git remote -v
origin    git://github.com/schacon/ticgit.git
pb    git://github.com/paulboone/ticgit.git

将数据从本地存储库推送到GitHub使用:

$ git push pb master

如果你还没有设置本地和/或远程存储库,请查看GitHub上的帮助和本书前面的章节。


打开你的GitHub仪表盘(如果你登录了,它在https://github.com/) 点击新建存储库 填空;点击创建存储库 按照随后出现的页面上的说明操作


如果你有本地源代码,你想添加到一个新的远程新git存储库,而不“克隆”远程,执行以下操作(我经常这样做-你在bitbucket/github中创建你的远程空存储库,然后推送你的源代码)

Create the remote repository, and get the URL such as git@github.com:/youruser/somename.git or https://github.com/youruser/somename.git If your local GIT repo is already set up, skips steps 2 and 3 Locally, at the root directory of your source, git init 2a. If you initialize the repo with a .gitignore and a README.md you should do a git pull {url from step 1} to ensure you don't commit files to source that you want to ignore ;) Locally, add and commit what you want in your initial repo (for everything, git add . then git commit -m 'initial commit comment') to attach your remote repo with the name 'origin' (like cloning would do) git remote add origin [URL From Step 1] Execute git pull origin master to pull the remote branch so that they are in sync. to push up your master branch (change master to something else for a different branch): git push origin master


正如JB非常正确地指出的那样,在GitHub上,只要简单地按照说明进行操作就变得非常容易。

下面是登录时使用http://github.com/new在GitHub上设置新存储库后显示的说明示例。

Global setup:

 Set up Git:
  git config --global user.name "Name"
  git config --global user.email email@gmail.com


Next steps:

  mkdir audioscripts
  cd audioscripts
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin git@github.com:ktec/audioscripts.git
  git push -u origin master


Existing Git repository?

  cd existing_git_repo
  git remote add origin git@github.com:ktec/audioscripts.git
  git push -u origin master


Importing a Subversion repository?

  Check out the guide for step-by-step instructions.

再简单不过了!!


当我尝试做皮特的步骤时,我在合并方面遇到了一些麻烦。这些是我最后的步骤。

Use your OS to delete the .git folder inside of the project folder that you want to commit. This will give you a clean slate to work with. This is also a good time to make a .gitignore file inside the project folder. This can be a copy of the .gitignore created when you created the repository on github.com. Doing this copy will avoid deleting it when you update the github.com repository. Open Git Bash and navigate to the folder you just deleted the .git folder from. Run git init. This sets up a local repository in the folder you're in. Run git remote add [alias] https://github.com/[gitUserName]/[RepoName].git. [alias] can be anything you want. The [alias] is meant to tie to the local repository, so the machine name works well for an [alias]. The URL can be found on github.com, along the top ensure that the HTTP button out of HTTP|SSH|Git Read-Only is clicked. The git:// URL didn't work for me. Run git pull [alias] master. This will update your local repository and avoid some merging conflicts. Run git add . Run git commit -m 'first code commit' Run git push [alias] master


其中一条评论提到了使用GitHub GUI,但它没有提供任何具体的使用帮助,并注意到大多数(如果不是所有的话)答案只在命令提示符下有用。

如果你想使用GitHub GUI,你可以按照以下步骤:

Click the "+" button and choose "Add Local Repository" Navigate to the directory with your existing code and click the "Add" button. You should now be prompted to "Create a new local Git repository here" so click the "Yes" button. Add your "Commit Summary" and "Extended description" as desired. By default, all of your files should selected with checkmarks already. Click the "Commit & Sync" button. Now you will be prompted to add the name and description of your project as well as which account to push it to (if you have multiple). Click the "Push Repository" button

在旋转GitHub图标后,您的源代码将属于本地存储库,并在您的GitHub帐户上推送/同步到远程存储库。所有这些都假设您之前已经设置了GitHub GUI、您的GitHub帐户和SSH密钥。


从Bitbucket都:

向上推一个现有的存储库。您的计算机上已经有了Git存储库。让我们把它推到Bitbucket:

cd /path/to/my/repo
git remote add origin ssh://git@bitbucket.org/javacat/geo.git
git push -u origin --all   # To push up the repo for the first time

我来这里是为了寻找一种简单的方法将现有的源文件添加到GitHub存储库中。我看到了@Pete完美完整的回答,心想“什么?!”一定有更简单的办法。”

这里有一个简单的方法,分为五个步骤(不需要控制台操作!)

如果你真的很赶时间,你可以读步骤3。其他的只是为了完整。

在GitHub网站上创建一个存储库。(我不会一步一步地给你讲解,以免侮辱你的智商。) 在本地克隆新的存储库。(你可以通过网站或桌面客户端软件来完成。) 在您的硬盘驱动器上找到新克隆的存储库,并像在普通目录中一样添加文件。 将更改同步回GitHub。 就是这样!

完成了!


添加一个GitHub存储库作为远程源(将[]替换为您的URL):

git remote add origin [git@github.com:...]

切换到你的主分支并复制它来开发分支:

git checkout master
git checkout -b develop

将你的开发分支推到GitHub的开发分支(-f表示force):

git push -f origin develop:develop

这里有一些关于如何初始化一个GitHub存储库,然后将您已经创建的代码推送到它的说明。第一组指令直接来自GitHub。

来源:https://help.github.com/articles/create-a-repo/

在任何页面的右上角单击,然后单击New repository。 为您的存储库创建一个简短、容易记住的名称。例如,“hello-world”。 可选地,添加存储库的描述。例如,“我在GitHub上的第一个存储库。” 选择创建公共存储库或私有存储库。 使用README初始化这个存储库。 创建存储库。

恭喜你!您已经成功创建了第一个存储库,并使用README文件对其进行了初始化。

现在,在这些步骤之后,你将希望将本地计算机上的代码推到刚刚创建的存储库中,并按照以下步骤执行:

Git初始化(在代码所在的根文件夹中) git add -A(这将添加你目录中所有要提交的文件和文件夹) git commit -am“第一个项目提交” git远程添加来源git@github.com:YourGithubName/your-repo-name.git(你会发现这个地址在GitHub存储库你刚刚创建的“ssh clone URL”在主页) Git push -u origin master

就是这样。你的代码现在会被推送到GitHub。现在,每当您想继续推送已更改的代码时,就这样做。

git commit -m "新改动" Git推送源master(如果master是你正在工作的分支)


我的解决方案:

问题是文件大小不能超过100M。

在迁移到github之前,在存储库中这样做:

git clone --mirror git://example.com/some-big-repo.git

wget http://repo1.maven.org/maven2/com/madgag/bfg/1.12.12/bfg-1.12.12.jar

mv bfg-1.12.12.jar bfg.jar

java -jar bfg.jar --strip-blobs-bigger-than 100M some-big-repo.git

cd some-big-repo.git

git reflog expire --expire=now --all && git gc --prune=now --aggressive

git push

准备好了!

现在再次使用工具https://github.com/new/import进行迁移

看到更多: 推到github回购时出错 而且 https://rtyley.github.io/bfg-repo-cleaner/

希望我能帮到你。:)


实际上,如果你选择在GitHub上创建一个空的repo,它会给你确切的指令,你几乎可以复制和粘贴到你的终端(在这个时间点):

…or create a new repository on the command line

echo "# ..." >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:<user>/<repo>.git
git push -u origin master

在git hub中创建存储库

允许通过GIT跟踪您的项目

使用CMD进入项目文件所在的文件夹->cd /automation/xyz/codebase 使用命令git status检查git初始化 如果你得到这个错误消息:fatal: Not a git repository(或任何父目录):.git,这意味着你当前所在的文件夹没有被git跟踪。在这种情况下,在项目文件夹中输入git init初始化git,然后执行添加和提交项目的过程。

如果您收到另一条错误消息,请仔细阅读其中的内容。如果你说“git”这个词不被识别,是不是说git没有安装在你的电脑上?它是否说你已经在git初始化的文件夹或子文件夹中?谷歌你的错误和/或输出来理解它,并找出如何修复它。

现在运行以下命令

#

echo "your git hub repository name" >> README.md git init git添加README.md Git commit -m "第一次提交" Git远程添加原点https:// # 当你第一次打开你的存储库时,你会得到上面的块 如果发生错误或在最后一个命令后没有发生任何事情,运行“git push -u origin master” 不要担心 去文件夹的代码是可用的,并通过git扩展推到git [URL],分支