git beginner Learning (ii): New branch/upload code/Delete branch

Source: Internet
Author: User

First, git new branch, upload code to the new branch I want to achieve the effect, that is, a parallel branch of multiple content, the main purpose is to facilitate the unified management of the same content of different projects, non-interference. : As long as I have a webpack_test project on GitHub, I'm building new branches and working on this project. If you are not sure how to create a new Webpack_test project, please refer to my previous article: Getting Started with Git (a): GitHub for Windows uploads local items to GitHub with the following steps: 1.1. Keep the base file (. git folder,. gitattributes,. Gitignore) under the Webpack_test item and replace the content with the new item. 1.2. Create and Switch branch local branch and push to remote server;
    • Git branch : There are several branches of our Git repository, and we are currently working on that branch, with an * number in front of the branch we are currently in. git branch-a : View Remote branch.
    • GIT branch Name: Creates a branch, and the pointer to that branch points to the most recent commit object, and to the same object as head. such as Git branch test, means to create a local test branch.
    • git checkout name: Switch to the destination branch, our default main branch is master.
    • Git checkout–b name: Create and switch branches.
    • Git push origin name: pushes the local name branch to the remote server.

1.3. Review the file change status and add a folder that needs to be uploaded locally
    • Git Status: View file change status. Before or after the file is added, we will use Git status to view the changed files (usually the changed files are shown in red).
    • git add fileName: Add a local folder to upload (code file add git Add file 1 file 2 .... )。
git add-a: [<path>] means to add file information from all tracked files in <path> to the index library that have been modified or deleted and all untracted. Ellipsis <path> representation., that is, the current directory. The status before the file is added, showing the files that were just deleted and added. : The status after the file is added, showing the files just deleted and added. : 1.4. Submit modification description and successfully push to remote branch
    • Git commit-m ' commits the data structure table design document to the Test branch ' for the modified description of the commit.
Tip: If you make an error in this step: git reset--hard HEADRoll back to the state before add
    • git push: The file is successfully submitted to the branch, and someone else can pull the file you submitted to him locally via the git pulls command.
Hint: Upload to remote server, if error fatal:the current branch test have no upstream branch. is because the submission to the branch needs to give--set-upstream origin < branch name; So execute the following statement:
    • git push--set-upstream origin Webpack-babel-loader
Submit a modification description. : Upload files to a remote server. : Then go to the browser to see the situation, found a new remote branch Webpack-babel-loader and uploaded the content belonging to it. Second, delete the branch 2.1. Delete local branch
    • Git branch-d name: Forces the local branch to be deleted (if there is an error indicating that the current branch is in use, you need to switch to the master branch before performing the delete). Like git checkout master, git branch-d webapack-babel-loader
2.2. Delete Remote Branch
    • git push origin:name, delete the remote branch, notice that the colon before the space is not less, the principle is to push an empty branch to the server, equivalent to delete the branch.
Summary: This article mainly explains how to create other branches on the basis of existing branches, and upload code to other branches, to achieve the purpose of non-interference, while facilitating the unified management of the same content. Then how to do the local branch and remote branch delete operation. Hope to help you, follow-up further content to be continued ...

git beginner Learning (ii): New branch/upload code/Delete branch

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.