Git
Install
sudo apt-get install git
Connect
- Generate ssh key in local system
ssh-keygen -t rsa -C "xxx@mail.com"
- 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
- Configure
git config --global user.name "linzhenyuyuchen"
git config --global user.email "xxx@mail.com"
- 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
-
Login Github
-
Create a repo with the same name
-
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