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

你可能感兴趣的:(2020-01-20 Git简单使用)