Git Using branches is a very important way of working. Sometimes, we may need to modify the branch name, perhaps because the branch name is too long, misspelled, irregular naming, etc. Next, we will introduce how to modify the branch name in Git.
- View branches
Before modifying the branch name, you first need to know all the current branches. Use the following command to view all current local branches:
$ git branch
A list of all local branches will be listed here. You can see that there will be an asterisk in front of the current branch, as shown below:
master * dev feature-1 feature-2
- Modify the local branch name
In Git, there are three main ways to modify the branch name, namely:
- Rename the branch
- Delete the branch and then create a new branch
- Create a new branch and then delete the old branch
Next, let’s introduce these three methods one by one.
2.1 Rename the branch
You can rename the branch through the following command:
$ git branch -m <old-branch-name> <new-branch-name></new-branch-name></old-branch-name>
Among them, "-m" means "move", that is, move/rename. What needs to be noted here is that remember to switch to other branches to perform operations, otherwise an error will be reported.
2.2 Delete the branch and create a new branch
This method is mainly divided into two steps:
- Delete the old branch
- Create a new one Branch
Step 1, delete the old branch, use the following command:
$ git branch -d <old-branch-name></old-branch-name>
This command will delete the specified old branch.
Step 2, create a new branch, use the following command:
$ git branch <new-branch-name></new-branch-name>
This will create a new branch and have the same parent node as the current branch.
2.3 Create a new branch and then delete the old branch
This method is also performed in two steps:
- Create a new branch
- Delete Old branch
Step 1, create a new branch:
$ git branch <new-branch-name> <old-branch-name></old-branch-name></new-branch-name>
This will create a new branch. The code of the new branch is exactly the same as the code of the old branch.
Step 2, delete the old branch:
$ git branch -d <old-branch-name></old-branch-name>
This will delete the old branch.
- Push the modified branch name
After modifying the local branch name, you need to synchronize the remote branch. Use the following command to push the modified branch name to the remote warehouse:
$ git push origin :<old-branch-name> $ git push origin <new-branch-name></new-branch-name></old-branch-name>
In the above command, ":" means to delete the specified branch from the remote warehouse, and then use the second command to push the new branch to the warehouse.
- Summary
The above are the three ways to modify the branch name in Git, you can choose according to your needs. It is worth noting that you must be careful when operating Git to ensure that you do not misoperate and cause unnecessary trouble.
The above is the detailed content of How to modify branch name in Git. For more information, please follow other related articles on the PHP Chinese website!

Answer: The steps involved in creating a Git project include: Install Git. Initialize the Git repository. Add files to the temporary storage area. Submit changes and add a description. (Optional) Create a remote repository. (Optional) Push (upload) changes to the remote repository.

How to add a public key to a Git account? Step: Generate an SSH key pair. Copy the public key. Add a public key in GitLab or GitHub. Test the SSH connection.

为 Git 添加环境变量的方法:修改 .gitconfig 文件。 Add env = KEY=VALUE in the [core] block. Save and exit the file.重新加载 Git 配置(git config --reload)。验证环境变量(git config --get core.env.MY_ENV_VAR)。

Use git to submit code separately, providing granular change tracking and independent work ability. The steps are as follows: 1. Add the changed files; 2. Submit specific changes; 3. Repeat the above steps; 4. Push submission to the remote repository.

To detect SSH through Git, you need to perform the following steps: Generate an SSH key pair. Add the public key to the Git server. Configure Git to use SSH. Test the SSH connection. Solve possible problems according to actual conditions.

To query the code uploaded to the Git repository, use the following command: View the commit record list: git log By commit hash query: git log <Commit hash>Search by commit information: git log -S <Search string>Query by file path: git log -S <Search string> -- <File path>Compare changes between two commits: git diff <Start commit hash> <End commit hash>View special

Connecting a Git server to the public network includes five steps: 1. Set up the public IP address; 2. Open the firewall port (22, 9418, 80/443); 3. Configure SSH access (generate key pairs, create users); 4. Configure HTTP/HTTPS access (install servers, configure permissions); 5. Test the connection (using SSH client or Git commands).

After committing to the wrong branch, you can resolve it by: Determine that the wrong branch creates a new branch, pointing to the correct branch apply the commit to the new branch Push the new branch to the remote repository to delete the wrong branch. Force update the remote branch


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools