Ubuntu 将本地项目上传到 github

Ubuntu 将本地项目上传到 github

刚刚开始使用 github,记录一下步骤。

  1. 首先在 github 上创建一个 repository, 不需要勾选添加 readme 文件。完成后如下图所示:
    这里写图片描述
    该 repository 会有一个专门的地址

  2. 在 Ubuntu 上使用如下指令:

    • git init
      使用 ll 可以查看生成了一个隐藏的.git文件

    • git add .
      其中,点 . 表示添加当前文件夹中的所有文件

    • git config –global user.email “[email protected]
      输入 github 的注册邮箱

    • git config –global user.name “Your Name”
      输入 github 的用户名

    • git commit -m “first commit”
      双引号内是上传时的注释内容

    • git remote add origin https://github.com/……………
      这里的网址,即对应前面 repository 的地址。
      如果是第一次添加的话,一般没什么问题。如果出现 “remote origin already exists” 的错误,可以先执行 git remote rm origin

    • git push -u origin master
      将文件推送到 github 上,此时会让你继续输入用户名和密码。 如果在创建 repository 的时候加入了readme,相当于对原仓库已做了修改,此时该命令会报错。可以用 git push -f origin master 来强制覆盖。

猜你喜欢

转载自blog.csdn.net/Design_by_TaoZ/article/details/80727568