2020-01-20 Git简单使用

Git简单使用

1基本命令

#克隆到本地
git clone https://gitee.com/kids0cn/Python.git 

#进入目录

cd Python

#更新远程仓库到本地
git pull

#写完代码把更改加到本地仓库
git add . #将所有更改加到缓存

#提交更改到本地
git commit -m "xx交作业"

#推送到远程
git push


2.分支操作

选择git仓库的不同分支

$git clone 仓库地址
$git branch -a #显示本仓库所含有的分支
$git checkout 分知名 #选择该分支

fork操作

fork了别人的代码,如何保持和原仓库同步

1.设置上游仓库

检查当前仓库有没有将源地址设置为上游

$git remote -v
origin https://github.com/Your_username/Your_fork.git(fetch)
origin https://github.com/Your_username/Your_fork.git(push)

将原仓库地址设置为当前仓库的上游upstream。

$git remote add upstream https://github.com/Original_owner/original_rep.git

再次检查当前仓库的上游信息

$git remote -v
origin https://github.com/Your_username/Your_fork.git(fetch)
origin https://github.com/Your_username/Your_fork.git(push)
upstream https://github.com/Original_owner/original_rep.git(fetch)
upstream https://github.com/Original_owner/original_rep.git(push)

2.同步上游仓库

$git fetch upstream

3.将上游仓库的代码合并到自己的仓库

$git merge upstream/master
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容