常用Linux命令
- cd
- cd…
- pwd 显示当前目录路径
- ls
- touch
- rm rm -r
- mv
- history
Git配置
git config --system --list
系统配置 在Git安装目录\Git\mingw64\etc\gitconfig
git config --global --list
用户配置 在C:\Users\用户名.gitconfig
设置用户名
git config --global user.name "name"
git config --global user.email"xx@qq.com"
右键添加git bash快捷键
https://www.jianshu.com/p/333aaff8bce8
工作区域
Working Directory 工作区 平时存放代码的地方
Stage/Index 暂存区 用于存放临时的改动 事实上只是一个文件
Repository/Git Directory 本地仓库 存放在.git目录中 有提交的所有版本的数据 HEAD指向最新放入仓库的版本
Remote 远程仓库 托管代码的地方
git管理的文件的三种状态 已修改modified、已暂存staged、已提交committed
实操
- 新建
本地新建
git init
远程克隆
git clone xxx.git
- 提交
git add .
git commit -m "提交信息"
- 分支
新建分支
git branch BRACH_NAME
切换分支
git checkout BRACH_NAME
删除分支
git branch -d BRACH_NAME
远程ssh设置
设置本机绑定SSH公钥 实现免密码登录 远程push
在C:\Users\username.ssh打开git
输入ssh-keygen -t rsa
rsa加密算法
拿到密钥后在个人主页中设置
上传自己的项目到远程
以码云为例
方法一
- 先在码云上新建仓库,生成远程仓库https://gitee.com/usernsme/xxx.git
- 然后在项目根目录下,将本地项目初始化
git init
- 然后add+commit
git add.
git commit -m "first commit"
- 上传至远程
git remote add origin https://gitee.com/xxx.git
git push -u origin "master"
方法二
- 码云新建仓库
- 在本地克隆
git clone https:xxx.git
- 修改后上传远程
master分支
git add .
git commit -m "xxx"
git push
直接在本地新建分支后想要上传至远程
新建分支
git branch feature-test
git checkout feature-test
touch test.txt
git add .
git commit -m "test"
git push //出错
fatal: The current branch feature-test has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin feature-test
不要直接git push,需要使用命令
git push --set-upstream origin feature-test
或者使用git push origin <本地分支名>:<远程分支名>
,该命令可以重新定义远程分支名
git push origin feature-test:feature-test //远程分支名为feature-test
git push origin feature-test:feature-test-remote //远程分支名为feature-test-remote
同理pull也可以git push origin <远程分支名>:<本地分支名>
git pull origin feature-test-remote:feature-test-local //拉取远程分支到本地,重命名为feature-test-local
其他问题
pull或者push reject解决方案
git pull origin master
git pull origin master --allow-unrelated-histories
git remote add origin https://gitee.com/imoonfish/dachuang.git
git push --set-upstream origin feature-test