Git 基本操作

Git

Install

sudo apt-get install git

Connect

  1. Generate ssh key in local system
ssh-keygen -t rsa -C "xxx@mail.com"
  1. Add ssh key to Github

Copy content in /home/lzy/.ssh/id_rsa.pub or /root/.ssh/id_rsa.pub to Github New SSH key

  1. Configure
git config --global user.name "linzhenyuyuchen"
git config --global user.email "xxx@mail.com"
  1. Test
ssh -T git@github.com

Local Repo

Make Repo

cd /dir/repo/
git init

Add

git add file.txt
git add .

Commit

git commit -m "comment"

Push

Make sure # Remote Repo Done before push

git push -u origin master

Remote Repo

Create Repo

  1. Login Github

  2. Create a repo with the same name

  3. Command under /dir/repo/

更换源

git remote rm origin
git remote add origin git@github.com:linzhenyuyuchen/Pytorch-SSD-EAD2020.git

git 分支管理

# 列出分支
git branch

# 删除分支
git branch -d branchname

# 创建分支
git branch branchname

# 切换分支
git checkout branchname

合并分支到master

git checkout master
git pull origin master
git merge branchname
git status
git push -u origin master

Error

hint: Updates were rejected because the remote contains work that you do

# 如果可以接受强制覆盖
git push -u origin master -f

# 若不想合并远程和本地的内容,则创建分支
git branch [name]
git push -u origin [name]

fatal: refusing to merge unrelated histories

git pull origin master --allow-unrelated-histories

总是出现要用户名和密码

git remote set-url origin git+ssh://git@github.com/linzhenyuyuchen/repo_name.git
posted @ 2020-07-24 15:19  林震宇  阅读(113)  评论(0编辑  收藏  举报