1、本地创建ssh key
ssh-keygen -t rsa -C "[email protected]"
默认保存到 /home/username/.ssh/id_rsa
验证是否成功
ssh -T [email protected]
2、配置用户信息,直接设成全局,下次就不用再设置
git config --global user.name "your name"
git config --global user.email "[email protected]"
3、本地仓库
git init
git add XXX
git . #添加所有文件
git commit -m "XXX"
git status
git diff #查看修改
4、远程仓库
git remote add origin [email protected]:yourName/yourRepo.git
git pull origin master # origin to master
git push origin master # master to origin
git pull 等同于 git fetch & git merge , 对于单个分支的可以直接用git pull
注:远程仓库一般用origin,可以改
二、分支管理
参考:http://www.runoob.com/git/git-branch.html
git branch #show branch
git branch <new branch> # add branch
git checkout <branch name> # cd branch
git checkout -b <new branch> # add & cd branch
git branch -d <branch name> # delete branch
git merge <branch name> # merge branch
git push origin <new branch> #push new branch to remote branch
git push origin :<new branch> #delete remote branch
or
git push origin -delete <new branch>
注:新建branch是master branch的一个快照
删除远程分支后,如果有对应的本地分支,本地分支并不会同步删除
git fetch
参考:https://www.yiibai.com/git/git_fetch.html
git fetch origin # fetch all branch
git fetch origin <branch>
#在本地以 主机名/分支名读取 eg: origin/master
git merge origin/master #合并到本地