git 新建工程

之前的一篇文章 https://www.cnblogs.com/wjw-blog/p/7189730.html,按照流程能搭建好git仓库,有时候会有一些小问题。

按照这个流程:
-在github 上新建一个仓库

-勾选 初始化 README.md文件

-ok, 生成 git仓库地址:http://userName/project.git

MAC上:

已有工程,在工程目录下执行:

$git init

$git add .

$git commit -m 'project init git'

$git remote origin master http://userName/project.git

$git pull origin master   (这句命令可能要换为git pull --rebase origin master, 因为你如果在创建远程仓库时同时创建了 README.md 有不带 --rebase的命令就不能把 README.md 下载下来,git 认为本地仓库和远程仓库不一致。之后也不能上传工程了)

$git push origin master

如果创建远程仓库的时候没有 创建 README.md. 就可以这样

$git init

$touch README.md  (本地创建 README.md 文件,先添加到本地仓库在上传到远程仓库)

$git add .

$git commit -m 'project init git'

$git remote origin master http://userName/project.git

$git pull origin master

$git push origin master

我推荐后一种方法,就是创建远程仓库时不要勾选创建 README.md, 因为这样创建好仓库,仓库下面会有命令提示

…or create a new repository on the command line

echo "# Project" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/wjwdive/Project.git
git push -u origin master

…or push an existing repository from the command line

git remote add origin https://github.com/wjwdive/Project.git
git push -u origin master

忘记的话命令直接粘贴复制,也不用担心错误。
远程创建README.md的时候是不会有命令提示的。
原文地址:https://www.cnblogs.com/wjw-blog/p/9506235.html