参考博客
初始化仓库
git init
添加文件
git add .
后面的·.·表示当前目录下的所有文件,也可以指定单独的文件。
提交代码
git commit -m "初始化提交"
添加远程仓库
git remote add origin https://github.com/xxx/xxx.git
pull代码
git pull origin master 正常来说就可以把代码pull下来了,我遇到的错误是
refusing to merge unrelated histories,这是因为本地和远程不是同一个源的问题,可以使用
git pull origin master --allow-unrelated-histories进行下载,其实就是添加 --allow-unrelated-histories这个参数。
push代码
push代码的时候一定要记得先pull一下,合并最新的代码。
git push origin master
新建分支
git branch newbranch
查看分支
git branch
切换分支
git checkout new branch
将新分支提交的改动合并到主分支上
git merge newbranch
删除分支
git branch -D newbranch
其他命令
git config --global user.name "设置用户名"
git config --global user.email "设置邮箱"
git config --list 查看当前的配置
git config 可以罗列出所有config属性