How to push my code to github?
0. git init (if didn't create git)
1. git add .
2. git commit -m "some comment"
3. git remote add origin "github repo ip address" (把repo加到 origin 这个标签上)
git branch -M main (-M 是move 重命名 把当前branch改为main 不一定要有)
git push -u origin main (把本地的main分支上传到origin对应的ip的main分支)
* git push 使用:
git push <远程主机名> <本地分支名>:<远程分支名>
(不写默认是同一个分支)
(git pull 是 <远程分支名>:<本地分支名>,即 <源>:<目的地>)
* git merge 使用:
git merge <分支名> 就是把 <分支名> merge 到当前分支
* git branch 使用:
** 查看所有的branch : git branch -a
** 复制branch : git branch -c <branch name>
** 删除branch : git branch -d <branch name>
** 创建branch : git checkout -b <branch name>
* error: remote origin already exists.
1. git remote -v: 查看现在连接的哪个repo
2. git remote rm origin: 删除原来的origin
3. git remote add origin "github repo ip address"
* 如果想回溯到某一个版本:
方法1: git reset --hard [commit id]
方法1 是退回到指定版本,并丢弃后面的提交
方法2: git checkout [commit id]
方法2 是迁出一个新分支
连接github:
当我要把我的分支合并到main分支上并提交:
1. 确认本地仓库最新:
git fetch origin
git checkout main
git pull origin main # 更新本地 main 分支到最新
git checkout your-branch-name
git pull origin your-branch-name # 更新本地工作分支到最新
2. 在本地 merge main 到 自己的分支:
git merge main
No comments:
Post a Comment