上传项目
- 进到项目文件夹:
将项目IDE配置信息删除(如,pycharm的.idea等。这样是为了保证IDE配置信息不会上传到Gitlab中, 也可以使用命令行在上传时将配置文件过滤, 个人觉得可视化删除方便些). - Command line instructions
Git global setup
git config --global user.name "yumingchen"
git config --global user.email "1051246404@qq.com"
Create a new repository
git clone git@github.com:yumingchen/hashSequence.git
cd Multi_crop
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder
cd existing_folder
git init
git remote add origin git@gitlab.sz.sensetime.com:chenyuming/Multi_crop.git
git add .
git commit -m "Initial commit"
git push -u origin master
Existing Git repository
cd existing_repo
git remote add origin git@gitlab.sz.sensetime.com:chenyuming/Multi_crop.git
git push -u origin --all
git push -u origin --tags
问题:
- github上传项目的时候报出git@github.com: Permission denied (publickey). fatal: Could not read from remote repository:(https://blog.youkuaiyun.com/weixin_44394753/article/details/91410463)
解决方法:具体见 https://blog.youkuaiyun.com/weixin_44394753/article/details/91410463
从github主页点击设置进入SSH and GPG keys - git 出现 fatal: refusing to merge unrelated histories 错误
首先 git push -u origin master 报错说:
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') be ...
远端觉得本地库和远程库不相关。可用git pull origin master解决。
但是git pull 失败 ,提示:fatal: refusing to merge unrelated histories
其实这个问题是因为 两个 根本不相干的 git 库, 一个是本地库, 一个是远端库, 然后本地要去推送到远端, 远端觉得这个本地库跟自己不相干, 所以告知无法合并
具体的方法, 一个种方法: 是 从远端库拉下来代码 , 本地要加入的代码放到远端库下载到本地的库, 然后提交上去 , 因为这样的话, 你基于的库就是远端的库, 这是一次update了
第二种方法:
使用这个强制的方法
git pull origin master --allow-unrelated-histories
后面加上 --allow-unrelated-histories , 把两段不相干的 分支进行强行合并
后面再push就可以了。
- git 查看远程分支、本地分支、创建分支、把分支推到远程repository、删除本地分支
1 查看远程分支
$ git branch -a
* br-2.1.2.2
master
remotes/origin/HEAD -> origin/master
remotes/origin/br-2.1.2.1
remotes/origin/br-2.1.2.2
remotes/origin/br-2.1.3
remotes/origin/master
2 查看本地分支
$ git branch
* br-2.1.2.2
master
3 创建分支
$ git branch test
$ git branch
* br-2.1.2.2
master
test
4 切换分支
git checkout branch-name
5 把分支推到远程分支
git add .
git push origin branch-name
6 删除本地分支 git branch -d xxxxx
7 删除远程分支
git branch -r -d origin/branch-name
git push origin :branch-name