2012-06-24 67 views
14
  • 我在github上创建了一个新的存储库。
  • 我选择了添加README.md的选项之一。
  • 我然后cd到我的硬盘上的项目。
  • 我运行git init:在/Users/myusername/github/myproject/.git/中初始化空的Git存储库
  • 我运行了“git add”。然后“混帐提交-m‘项目文件’”,这本回应:承诺没有显示在github上

    [master (root-commit) ca52fe0] project files 
    981 files changed, 257939 insertions(+), 0 deletions(-) 
    create mode 100644 index.php 
    create mode 100644 license.txt 
    create mode 100644 readme.html 
    create mode 100644 wp-activate.php 
    ... 
    
  • 然后我跑了“git的远程添加原产https://github.com/myusername/myproject.git
  • 然后我跑了“混帐推起源大师”
  • 然后我跑了“git状态”,表示什么都没有提交

但我看回购和我的“我的项目文件”提交不存在。所以然后我跑git拉,得到这个:

You asked me to pull without telling me which branch you 
want to merge with, and 'branch.master.merge' in 
your configuration file does not tell me, either. Please 
specify which branch you want to use on the command line and 
try again (e.g. 'git pull <repository> <refspec>'). 
See git-pull(1) for details. 

然后git推,并再次检查,仍然我的提交不在github回购。我唯一能看到提交的时候是当我运行“git log”的时候:

MacBook-myproject myusername$ git log 
commit ca52fe090e6dbf1b6aa6ee51c3283efbe7549904 
Author: User <myemailaddress> 
Date: Sat Jun 23 19:22:05 2012 -0400 
project files 

我跟着github的方向,我可以做得最好。我究竟做错了什么?

+0

你的'origin'版本库URL是否正确?试试'$ git remote -v'来验证。 –

+0

当我运行上面的命令,我得到这个:原始\t https://github.com/username/gitproject.git(fetch) 原点\t https://github.com/username/gitproject.git(推) – JohnMerlino

+1

你是从字面上得到这些URL还是你改变“用户名”和“gitproject.git”是更通用的? –

回答

11

您的Github上库被创建后(即你可以在Github上查看它),那么你应该已经有了:

  • 本地资源库设置:git init
  • README文件创建并添加到资料库:

touch README
git add README
git commit -m 'first commit'

  • 远程叫origin链接到你的资料库:

git remote add origin https://github.com/username/repo.git

  • 的初始推力,其复制本地自述文件到您的Github上库:

git push -u origin master

如果您可以查看在Github仓库,然后它已成功创建。在这种情况下,您可能使用在线编辑工具在Github上编辑了自述文件,这会导致您的远程和本地分支发生分歧。在将本地更改推送到Github之前,您需要获取或拉取远程更改,在本地合并更改(与pull自动合并),然后推送到远程。

见临的Git:Fetching and Pulling from Your Remotes

3

当你创建你选择将初始化远程包含README.md文件GitHub上的仓库。下一步将在您的终端中运行git clone https://github.com/username/repo.git。此时,您在GitHub存储库上拥有本地副本,因此您将随后移入项目文件。运行git add *,然后git commit -m 'first commit',然后git push origin master。您的更改现在应该可以在GitHub上看到。