git创建本地分支并推送到远程

1.查看本地分支

    git branch


2.查看远程分支

git branch -a


3.创建本地分支并切换到分支

git branch dev

git checkout dev

4.将修改提交到本地仓库

git add ./

git commit -m "描述"

5.将分支修改同步到远程分支

git push origin HEAD:refs/for/dev

origin: 远程库名字

HEAD: 指向正在工作的本地分支的指针

refs/for: 意义在于我们提交代码到服务器之后是需要经过code review之后才能进行merge的

6.如果执行git push origin HEAD:refs/for/dev命令时有如下报错:

$ git push origin HEAD:refs/for/dev

Enumerating objects: 31, done.

Counting objects: 100% (31/31), done.

Delta compression using up to 8 threads

Compressing objects: 100% (13/13), done.

Writing objects: 100% (17/17), 3.39 KiB | 694.00 KiB/s, done.

Total 17 (delta 9), reused 0 (delta 0)

remote:Resolving deltas: 100% (9/9)

remote:Processing changes: refs: 1, done

remote:ERROR: commit f0635bd: missing Change-Id in message footer

remote:

remote: Hint: to automatically insert a Change-Id, install the hook:

remote: gitdir=$(git rev-parse --git-dir); scp -p -P 29418 [email protected]:hooks/commit-msg ${gitdir}/hooks/

remote: and then amend the commit:

remote: git commit --amend

remote: To ssh://192.168.180.150:29418/bigdata-asuperagent

! [remote rejected] HEAD -> refs/for/dev (commit f0635bd: missing Change-Id in message footer)

error: failed to push some refs to 'ssh://[email protected]:29418/bigdata-asuperagent'


需要执行以下操作:

1.撤销本地修改,回到上次提交之前

git reset HEAD~

2.引入控制脚本(钩子)

scp -p -P 29418 [email protected]:hooks/commit-msg .git/hooks/

3. git add ./

    git commit -m ""

    git  push origin HEAD:refs/for/dev

你可能感兴趣的:(git创建本地分支并推送到远程)