git create a new branch and push (push) to the remote warehouse
For example, you already have a project, and the project has been pushed to a remote warehouse. Now the project needs to develop a new function, or to make some changes, you need to create a new branch.
The steps are as follows:
I use gitLab as an example here
1. Create a new branch in the remote warehouse first
- New branch
- The name of the remote branch
2. Create a new local branch
Note: Before creating a new branch, make sure that all changes to the current branch have been submitted cleanly, and ensure that the workspace is clean
git status
Command first check the status of the current branch
$ git status
On branch test
Your branch is up to date with 'origin/test'.
nothing to commit, working tree clean
The above means that you are in a test
branch now , without any commits, and the workspace is clean
- At this time, you can create a new local branch and use the
git checkout -b 分支名
command
git checkout -b bigScreen
After pressing Enter, a new branch is created locally, and the git status
situation is checked through commands. At this time, the local bigScreen branch has been created and switched to the changed branch.
$ git status
On branch bigScreen
nothing to commit, working tree clean
- After making changes to the code, check the status again, it prompts that a file has been modified, use the
git add .
command to update the content to be submitted
$ git status
On branch bigScreen
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/components/login.vue
no changes added to commit (use "git add" and/or "git commit -a")
git add .
- By
git commit -m '本次提交说明文字'
submitting content to the local store to the local staging area
git commit -m '2021.01.28 删除了logo图标'
[bigScreen e3333d9] 2021.01.28 鍒犻櫎浜唋ogo鍥炬爣
1 file changed, 1 insertion(+), 1 deletion(-)
- By
git push origin 远程仓库分支名
the locally stored content submitted to a remote repository that just the new branch up
git push origin bigScreen
Completed the new branch and submitted it to the remote warehouse