1.安装git
sudo apt get install git
2.然后在src文件夹中初始化git仓库
git init
3. 配置提交代码时的用户信息:
git config --global user.email 573705543@qq.com
git config --global user.name"haigujiujian"
home 目录下会生成一个.gitconfig
4.为github账号添加ssh秘钥
sudo apt-get install openssh-server openssh-client
sudo /etc/init.d/ssh restart
生成秘钥:ssh-keygen -C '573705543@qq.com' -t rsa
ssh -v git@github.com
cat ~/.ssh/id_rsa.pub获取秘钥
添加秘钥到上面的SSH and GPG KEYS到github的SSH and GPG keys里面
将本地仓库关联到GitHub新建的仓库上:
git remote add origin https://github.com/Love-LG/Javaweb-firstcup-war
当然也可以更换仓库 git remote rm origin 就可以了
然后就是git add *
git commit -m " first commit"
然后就可以 git push origin master
ssh -T git@github.com 可以用于检测与github仓库是否已经连接上
git新建分支并提交本地代码到远程分支
step1,在本地新建分支
git branch newbranch
step2:把本地分支push到远程
git push origin newbranch
step3:切换到该分支
git checkout newbranch
step4:查看本地修改
git status
step5:添加本地修改
git add .
step6:commit修改
git commit -m 'XXXX'
step7:push代码
git push