github\gitee与本地仓库关联、推送常用

拉取远程仓库代码

克隆远程代码会自动与远程服务器关联,无需进行手动关联
1.执行远程克隆命令

$ git clone  xxx    后接https地址或者ssh地址都可
2.本地文件新增后提交远程仓库操作:
$ git add .  
$ git commit -m “xxxx”     
$ git push 推送至远程仓库

 本地仓库关联远程仓库

该情况适用于本地无创建仓库

创建本地仓库并完成初次提交
$ mkdir xxx
$ cd xxx
$ git init 
$ touch README.md
$ git add README.md
$ git commit -m "first commit"
关联远程仓库
$ git remote add origin https://xxxxxxxx
执行远程推送命令
$ git push -u origin "master"

该情况适用于本地已创建有与远程同名仓库

1.进入本地仓库
$ cd xxxx
2.关联远程
$ git remote add origin https:xxxxxx
3.查看远程库
$ git remote -v
4.执行推送
$ git push -u origin "master"

 本地分支与远程分支同步

$ git branch -a 可查看远程分支    
$ git branch 仅显示本地分支

1.创建本地分支并切换到该分支(假设该分支名为aaa)
$ git checkout -b aaa

2.提交本地分支中文件
$ git add .    
$ git commit -m “xxx”

3.本地分支推送远程
$ git push 
出现错误:
fatal: The current branch ask has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push –set-upstream origin aaa

4.使用  $ git push –set-upstream origin aaa   即可成功推送本地分支到远程