Git creates a new branch locally and pushes it to the remote branch

Source: Internet
Author: User
Tags commit git commands

Common git commands

First, create a branch: Branchname represents the new branch name, otherbranchname remote branch name

1. Create a new branch based on the current branch, Branchname represents the new branch name

Git branch Branchname

2. Create new branch based on other remote branches

Git branch branchname origin/otherbranchname

3. Create new branch based on other remote branches and switch to newly created branch

git branch–b branchname origin/otherbranchname

II. Submission of new branch

1. Submit the branch to the remote end

git push origin/branchname

2. Commit success: View all branches on remote side

Git branch–r

3. View Local Branches

Git branch

4. View local and remote branches

Git branch–a

Remove a branch: Be careful not to operate on the branch you are about to delete

1. Delete local branch, only branch not submitted to remote

Git branch–d origin/branchname

2. Delete Remote Side Branch

Git branch–r–d origin/otherbranchname

git push origin:otherbranchname Note: The space after Origin

3. Force the Delete branch to change-D to-D

Iv. Switch Branches: Note that all the modified files need to be submitted before switching branches

1. Switch branches

Git checkout-b branchname to create a branch locally and switch to that branch

V. Merging of branches

1. Merge the Branch (Branchname) in development into the main branch (Otherbranchname)

First, the Branchname branch is switched to the Otherbranchname branch.

git checkout Origin/otherbranchname

Merge

git merge Branchname

If there is a conflict, you can call Gitstatus view

Resolve the conflict, and then call git Add or git rm to save the resolved file.

2. Merging the branch (Branchname) in development into the main branch (Otherbranchname), without preserving the merge log

First, the Branchname branch is switched to the Otherbranchname branch.

git checkout Origin/otherbranchname

Merge

Git rebase branchname

3, git merge–no–ff branchname

You can save your previous branch history. Better view of merge history, and branch status.

Gitmerge does not display feature, leaving only a single branch record.

Vi. Other Orders

1. Get remote Branch information to local

git fetch

2. View All commands

Git help

3. Revocation of the most recent submission

git reset head^

4. See which branches are merged into the current branch to

Git branch–merged

5. See which branches are not merged into the current branch

Git branch–no–merged

6. View all branches last commit

Git branch–v

7. Renaming branches

Git branch–m oldbranchnamenewbranchname

8. Force Rename Branch

Git branch–m oldbranchnamenewbranchname

9. View the merge Help document

Git merge–h/git merge--help

10. Submit the local branch as the master branch

git push originbranchname:master

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.