Git 基础 - 克隆远程仓库到本地,修改后推送到远程

Posted wooluwalker

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Git 基础 - 克隆远程仓库到本地,修改后推送到远程相关的知识,希望对你有一定的参考价值。

 克隆现有的远程仓库到本地

[@wooluwakerdeMBP:gitLab]$ pwd
/Users/walker/work/gitLab

[@wooluwakerdeMBP:gitLab]$ git clone ssh://git@******.git #将远程仓库克隆到本地,会新创建wenjian目录

[@wooluwakerdeMBP:wenjian (master)]$ git remote -v #查看远程信息
origin    ssh://git@******.git (fetch)
origin    ssh://git@******.git (push)

[@wooluwakerdeMBP:gitLab]$ cd wenjian/
[@wooluwakerdeMBP:wenjian (master)]$

[@wooluwakerdeMBP:wenjian (master)]$ echo "2019年_******项目代码" >> REAMME.md

[@wooluwakerdeMBP:wenjian (master)]$ git add .

[@wooluwakerdeMBP:wenjian (master)]$ git commit -m添加项目说明

[@wooluwakerdeMBP:wenjian (master)]$ git push -u origin master #将本地master分支修改的代码提交到远程master分支,-u参数:加上一次之后,后续只需要git push 即可,不需要再加上 origin master 
Branch master set up to track remote branch master from origin.

# 在gitlab 的 web页面上可以看到最新的推送

 

将远程dev分支合并到远程master分支

git checkout -b dev origin/dev #在本地创建并切换到dev分支,并连接到远程的dev分支

[@wooluwalkerdeMacBook-Pro:wenjian (dev)]$ git pull origin dev

[@wooluwalkerdeMacBook-Pro:wenjian (dev)]$ ll # 远程dev分支内容已经pull下来
total 16
drwxr-xr-x  10 walker  staff   320B  2  2 12:59 .
drwxr-xr-x   6 walker  staff   192B  2  2 12:38 ..
-rw-r--r--   1 walker  staff   6.0K  2  2 12:59 .DS_Store
drwxr-xr-x  15 walker  staff   480B  2  2 13:02 .git
-rw-r--r--   1 walker  staff     0B  2  2 12:59 README.md
-rw-r--r--   1 walker  staff     0B  2  2 12:59 __init__.py
drwxr-xr-x   7 walker  staff   224B  2  2 12:59 __pycache__
drwxr-xr-x   9 walker  staff   288B  2  2 12:59 data
drwxr-xr-x   6 walker  staff   192B  2  2 12:59 merge
drwxr-xr-x   8 walker  staff   256B  2  2 12:59 utils

[@wooluwalkerdeMacBook-Pro:wenjian (dev)]$ git checkout master
Switched to branch master
Your branch is up to date with origin/master.

[@wooluwalkerdeMacBook-Pro:wenjian (master)]$ ll # master分支并没有dev分支的内容
total 8
drwxr-xr-x   4 walker  staff   128B  2  2 13:04 .
drwxr-xr-x   6 walker  staff   192B  2  2 12:38 ..
drwxr-xr-x  15 walker  staff   480B  2  2 13:04 .git
-rw-r--r--   1 walker  staff    34B  2  2 13:04 README.md
[@wooluwalkerdeMacBook-Pro:wenjian (master)]$ 

[@wooluwalkerdeMacBook-Pro:wenjian (master)]$ git merge dev #将本地dev分支合并到本地master分支

[@wooluwalkerdeMacBook-Pro:wenjian (master)]$ git status #本地master分支比远程master分支提前
On branch master
Your branch is ahead of origin/master by 4 commits.
  (use "git push" to publish your local commits)

[@wooluwalkerdeMacBook-Pro:wenjian (master)]$ git push # 将本地master分支推送到远程master分支

 

以上是关于Git 基础 - 克隆远程仓库到本地,修改后推送到远程的主要内容,如果未能解决你的问题,请参考以下文章

Git 第八章 IDEA集成GitHub -- IDEA集成GitHub(推送代码到远程仓库 & 拉取代码到本地仓库 & 克隆远程仓库代码到本地)

浅克隆后推送到 github

git实用的操作命令

git能直接把本地仓库推送到远程仓库吗?

Git学习

Git常用命令