github仓库的创建请看:https://www.linuxidc.com/Linux/2017-11/148628.htm
仓库的创建做一下记录:
点击右上角settings -> SSH and GPG keys -> new sshkeys
在ubuntu下运行:
ssh-keygen -t rsa -C "youremail@example.com"
cd /root/.ssh
这里就有一个id_rsa 和id_rsa.pub文件
将id_rsa.pub的内容复制到仓库new_keys即可
1 删除远程仓库的文件夹
git rm -r --cached test
git commit -m "删除test文件夹"
git push
2 创建并切换到develop分支
git checkout -b develop
3 查看所在分支
git branch
4 添加文件到分支
添加文件:
git add test/test.txt
加入分支:
git commit -m "添加test.txt文件"
上传分支到远程仓库:
git push origin develop
5 查看修改情况
git log
commit ec4751a3914199a1cd8bf686493e0b6701f9086e (HEAD -> develop, origin/develop)
6 版本回退
回退到上一个版本
git reset --hard
指定退到某个版本
git reset --hard ec4751a(版本的commit ID 前几位)
7 创建一个git项目
8 删除本地分支
git branch -d develop
9 删除远程创库分支
git push origin --delete develop
10 查看当前用户信息
git config user.name
git config user.email
11 提交
git add xxx文件
git commit -m "添加的接口名字,尽量详细说明"
git checkout master 跳到主分支
git merge 合并分支到主分支,完成项目更新
12 删除远程仓库的文件
git rm test.txt (删除文件)
git rm -r test (删除文件夹)
git commit -m "delelte files"
git push origin master/develop
13、上传文件失败
To github.com:gg-fu/CommonProgramming.git
! [rejected] develop -> develop (non-fast-forward)
error: failed to push some refs to 'git@github.com:gg-fu/CommonProgramming.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决: git pull --rebase origin develop
git push -u origin develop
14、git修改本地分支后,切换到主分支会同时修改主分支。怎么让两个分支在合并之前是独立的呢?
在切换分支之前隐藏修改的内容:git stash
在其他分支修改完成后,切换回来查看隐藏的内容:git stash list
恢复修改:git stash apply stash@{0}