- cd到希望存储代码的目录路径,新建本地仓库
cd ~/<your path>
git init
- 配置用户名和邮箱
git config user.name 'your name'
git config user.email 'your email'
- 在gitee平台创建工程对用的仓库
略。。。
- 指定仓库地址与名称
git remote add origin https://gitee.com/<your name>/renran.git
git push -u origin "远程分支名"
- 使用ssh连接仓库
ssh-keygen -t rsa -C 'your email'
cat /home/<your path>/.ssh/id_rsa.pub
git remote remove origin
git remote add origin git@gitee.comvetra/<your name>.git
- 提交代码
git add .
git commit -m "描述说明"
git push -u origin 远程分支名
- 撤销commit及add操作
git reset --hard HEAD~1
- 查看当前分支
git branch -a
- 创建本地分支
git fetch origin branch1:branch2
- 删除本地分支
git branch -D 2.4.5
- 创建新的分支并提交新分支
git checkout -b newB
git push -u origin newB
- 创建本地分支与远程分支关联
git fetch --all
git branch -a
git checkout -b <Local Branch Name> origin/<Branch Name>
- 创建本地分支与远程分支关联(常用)
首先,获取远程所有分支
git fetch
创建与远程分支关联的本地分支(可以同名,也可以不同名;建议同名,方便管理)
git checkout -b 本地分支名 origin/远程分支名
- 提交单个文件到分支
git commit <file> -m "your comment"
git push