一、创建本地仓库并提交代码
git init
初始化一个新仓库。git add
git commit
把文件提交到本地仓库。
二、拉取远程仓库
先使用git remote add
命令添加一个远程仓库,仓库地址:https://github.com/madawang/vazd
。
1 2 3 4 |
> git remote add origin https://github.com/madawang/vazd > git remote -v # 查看远程仓库 origin https://github.com/madawang/vazd.git (fetch) origin https://github.com/madawang/vazd.git (push) |
使用git pull
拉取远程文件,会出现以下信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
> git pull remote: Counting objects: 6, done. remote: Compressing objects: 100% (2/2), done. remote: Total 6 (delta 0), reused 3 (delta 0), pack-reused 0 Unpacking objects: 100% (6/6), done. From https://github.com/madawang/vazd * [new branch] master -> origin/master There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details. git pull <remote> <branch> If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/<branch> master |
表示本地分支和远程分支没有建立联系,不能直接pull
,需要先把本地分支和远程分支建立联系:
1 2 |
git branch --set-upstream-to=远程连接名/远程分支的名字 本地分支的名字 git branch --set-upstream 本地分支名字 远程连接名/远程分支名字 |
对于本地项目使用git branch --set-upstream master origin/master
即可。
如果git版本过新,还可能出现以下错误:
1 2 |
fatal: the "--set-upstream" option is no longer supported. Please use "--track" or "--set-upstream-to" instead. |
原因是--set-upstream
选项不再被支持,需要使用--track
选项:
1 2 3 |
> git branch --track master origin/master # 出现下面信息表示关联成功,然后就可以用git pull了。 Branch "master" set up to track remote branch "master" from "origin". |
1 2 3 4 |
> git pull origin master # git pull From https://github.com/madawang/vazd * branch master -> FETCH_HEAD Already up to date |
三、提交本地仓库内容到远程仓库
把本地代码先提交到本地仓库,使用git push
把代码提交到github
,会弹出对话框要求输入账号密码。
1 2 3 4 5 6 7 8 9 |
> git push Counting objects: 12, done. Delta compression using up to 4 threads. Compressing objects: 100% (7/7), done. Writing objects: 100% (12/12), 2.14 KiB | 1.07 MiB/s, done. Total 12 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), done. To https://github.com/madawang/vazd.git 82f3254..f20d28f master -> master |
提交后github
中的文件信息:
评论