0设置用户名,并且在github建立相应的仓库。
git config --global user.name “your name”(代表github用户名)
git config --global user.email “your_email@youremail.com”(github邮箱
1 git init
2 git add .
3 git commit -m “需要记录的”
4 git remote add origin git@github.com:***/test.git
5 git pull origin master
6 git push -u origin master
出现问题总结:
一般而言上述六个步骤就可以解决了,但是有的时候总会出现各种问题:
问题1:仓库分支和本地分支名称不匹配。
解决办法:修改本地仓库名称:
git branch -m "oldname" "newname"
问题2:git pull报错"fatal refusing to merge unrelated histories"
解决方法:
git pull origin master --allow-unrelated-histories
问题3:出现Updates were rejected because the tip of your current branch is behind
解决办法:
使用强制命令
git push -u origin master -f
or
git push --all -f origin
问题4:自动生成的 merge commit,那么只要在执行 git pull origin master 的时候带上 --rebase 即可:
git pull --rebase origin master
问题5:使用 git commit 命令后,进入类似vim的界面,也即nano界面,不知道怎么退出:
使用ctr+x后,进入退出选项,然后退出。
问题6:查看本地分支
git branch
问题6:查看远程分支
git branch -r
问题7:查看所有分支
git branch -a
推送本地分支到远程分支
git init
git add .
git commit -m 'commit '
git remote add CMO https://github.com/XXX.git # CMO为对应仓库的别名
git push CMO master -f # 强制推本地master到远程的CMO项目下的master分支下
```bash
…or create a new repository on the command line
echo "# Robust-Gymnasium-Demos" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:XXX.git
git push -u origin main
…or push an existing repository from the command line
git remote add origin git@github.com:XXX.git
git branch -M main
git push -u origin main
**参考资料**
[1] https://www.jianshu.com/p/004f47f908c5
[2] https://juejin.cn/post/6844903920641409038
[3] https://juejin.cn/post/6844903895160881166
[4] https://blog.csdn.net/u010168781/article/details/81902689
[5] https://www.jianshu.com/p/c70ca3a02087