A code branch switching method, device, apparatus and storage medium
By automating the judgment and processing of branch switching logic, the problem of version chaos caused by manual operation errors in Git branch management is solved, realizing a more efficient and secure branch switching process and reducing development risks.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 广州鼎甲计算机科技有限公司
- Filing Date
- 2025-07-28
- Publication Date
- 2026-05-08
AI Technical Summary
In multi-task parallel development scenarios, Git branch management is prone to version chaos and errors due to manual operation mistakes, especially when switching branches without committing changes, which can easily lead to the loss of functionality.
By responding to the code copy switching command of the target branch, it iterates through all copies of the code repository, determines whether the target branch exists, and if not, switches to the target branch when both the current branch and the remote branch meet the conditions; otherwise, it switches to the preset default branch, or creates a new copy and switches to the directory of the new copy.
Automated branch switching reduces manual operation errors, improves development accuracy, ensures the security and consistency of branch switching, and reduces version chaos and operational errors.
Smart Images

Figure CN120848855B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software development technology, and more specifically, to a method, apparatus, device, and storage medium for switching code branches. Background Technology
[0002] In software development, Git, as a mainstream distributed version control system, supports branch management, but it has limitations in multi-task parallel development scenarios. Developers often need to maintain multiple repository copies to avoid interference from intermediate artifacts when switching branches, but they have to manually manage copy synchronization and switching, which can easily lead to version chaos due to operational errors. At the same time, if there are uncommitted changes before switching branches, missed commits can easily cause feature loss, significantly increasing the risk of errors.
[0003] Therefore, how to automate code branch switching to reduce manual operation errors and improve development accuracy is an issue that needs attention. Summary of the Invention
[0004] In view of the above problems, this application provides a method, apparatus, device and storage medium for switching code branches to reduce manual operation errors and improve development accuracy.
[0005] To achieve the above objectives, the following specific solutions are proposed:
[0006] A code branch switching method, including:
[0007] In response to the code copy switching command for the target branch, traverse all copies of the code repository and determine whether there is a copy in the target branch;
[0008] If not, then if the target branch exists on the remote end of the code repository and the first condition is met in the current branch and the second condition is met in the remote end, then the current branch is switched to the target branch. The first condition is that there is no uncommitted or unpushed code in the working directory of the current branch, and the second condition is that the remote end contains all the code commit records of the current branch.
[0009] If the target branch does not exist at the remote end, the current branch is switched to the preset default branch.
[0010] Optionally, the method further includes:
[0011] If the current branch does not meet the first condition or the remote end does not meet the second condition, a new copy is created and the current working directory is switched to the directory of the new copy;
[0012] Determine whether the branch containing the new copy exists at the far end;
[0013] If so, switch the current branch to the target branch;
[0014] If not, the current branch will be switched to the preset default branch.
[0015] Optionally, creating a new copy includes:
[0016] Create an empty copy of the project;
[0017] Copy the working code from the current working directory to the project copy;
[0018] In the directory of the project copy, clear the intermediate artifacts generated during the copying of the working code to the project copy to obtain a new copy.
[0019] Optionally, creating an empty project copy includes:
[0020] Iterate through all existing project copies and determine the maximum name for each project copy;
[0021] Name the project based on the maximum value and create an empty copy.
[0022] Optionally, the method further includes:
[0023] If a target copy exists in the target branch, then switch the current working directory to the directory of the target copy.
[0024] A code branch switching device, comprising:
[0025] The target branch replica determination unit is used to respond to the code replica switching instruction of the target branch, traverse all replicas of the code repository, determine whether there is a replica in the target branch, and if not, execute the target branch switching unit;
[0026] The first target branch switching unit is used to switch the current branch to the target branch when the current branch meets the first condition and the remote end of the code repository meets the second condition, and if the target branch exists on the remote end. The first condition is that there is no uncommitted or unpushed code in the working directory of the current branch, and the second condition is that the remote end contains all the code commit records of the current branch.
[0027] The first default branch switching unit is used to switch the current branch to the preset default branch if the target branch does not exist at the far end.
[0028] Optionally, the device may also include:
[0029] The new copy creation unit is used to create a new copy and switch the current working directory to the directory of the new copy if the current branch does not meet the first condition or the remote end does not meet the second condition.
[0030] The remote branch existence determination unit is used to determine whether the branch where the new copy is located exists in the remote branch. If it does, the second target branch switching unit is executed; otherwise, the second default branch switching unit is executed.
[0031] The second target branch switching unit is used to switch the current branch to the target branch;
[0032] The second default branch switching unit is used to switch the current branch to the preset default branch.
[0033] Optionally, the new copy creation unit includes:
[0034] An empty copy creation unit is used to create an empty project copy if the current branch does not meet the first condition or the remote end does not meet the second condition.
[0035] The code copying unit is used to copy working code from the current working directory to the project copy;
[0036] An intermediate product removal unit is used to remove intermediate products generated during the copying of the working code to the project copy in the project copy's directory, thereby obtaining a new copy.
[0037] Optionally, the empty copy creation unit includes:
[0038] The maximum value naming determination unit is used to traverse all existing project copies and determine the maximum value name for each project copy.
[0039] An empty copy naming creation unit is used to create an empty project copy based on the maximum value.
[0040] Optionally, the device may also include:
[0041] The direct switching unit is used to switch the current working directory to the directory of the target copy if a target copy exists in the target branch.
[0042] A code branch switching device, including memory and processor;
[0043] The memory is used to store programs;
[0044] The processor is used to execute the program and implement the various steps of the code branch switching method described above.
[0045] A storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the code branch switching method described above.
[0046] By employing the above technical solution, this application, in response to the code copy switching command for the target branch, traverses all copies of the code repository to determine if any copy exists on the target branch. If not, and if the current branch meets the first condition and the remote repository meets the second condition, then if the target branch exists on the remote repository, the current branch is switched to the target branch. The first condition is that there is no uncommitted or unpushed code in the current branch's working directory, and the second condition is that the remote repository contains all code commit records for the current branch. If the target branch does not exist on the remote repository, the current branch is switched to the preset default branch. Therefore, when a branch needs to be switched, the system automatically determines how to switch branches, preventing developers from switching branches without committing code, reducing manual operation errors, and improving development accuracy. Attached Figure Description
[0047] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the scope of this application. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings:
[0048] Figure 1 This is a schematic diagram of a first process for implementing code branch switching, provided in an embodiment of this application.
[0049] Figure 2 This is a schematic diagram illustrating a second process for implementing code branch switching, as provided in an embodiment of this application.
[0050] Figure 3 A schematic diagram of a process for creating a new copy is provided in an embodiment of this application;
[0051] Figure 4 This is a schematic diagram illustrating a third process for implementing code branch switching, provided in an embodiment of this application.
[0052] Figure 5 A schematic diagram of a device structure for implementing code branch switching, provided in an embodiment of this application;
[0053] Figure 6 This is a schematic diagram of the structure of a device for implementing code branch switching, provided in an embodiment of this application. Detailed Implementation
[0054] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0055] The proposed solution can be implemented based on a terminal with data processing capabilities, such as a computer, cloud, or server.
[0056] Next, combined Figure 1 The code branch switching method described in this application may include the following steps:
[0057] Step S110: In response to the code copy switching instruction of the target branch, traverse all copies of the code repository.
[0058] A code repository is a source code repository managed using Git, containing the project's entire version history. A code repository exists as a directory containing a `.git` directory for version control. A copy of a code repository can be an independent copy created by copying an existing Git repository directory, containing complete code and version information. Different copies can independently switch branches, build, or test without affecting each other. A branch represents a version path in Git used for parallel development. Each branch can have a different commit history, allowing developers to experiment, fix issues, or develop new features on different branches.
[0059] Specifically, users can enter a command specifying the target branch name, which triggers a switch to a copy of the current branch. The target branch can represent the Git branch name the user wishes to switch to, and can be received as a parameter by the switch command to find or create a matching repository copy.
[0060] Understandably, by traversing all replicas, it is possible to comprehensively check whether there are replicas already in the target branch, ensuring that existing replicas can be reused directly, avoiding duplicate creation, and reducing resource consumption.
[0061] Step S120: Determine if there is a copy in the target branch. If not, proceed to step S130.
[0062] Specifically, the target branch may or may not contain a copy. If the target branch is found but no copy is found within it, the copy may exist at the remote end of the code repository. The remote end is a general container that can contain commits of all copies.
[0063] Alternatively, if the target branch is not found, step S130 can be executed.
[0064] Step S130: Determine whether the first condition and the second condition are met simultaneously. If so, proceed to step S140.
[0065] Specifically, we can determine whether the current branch meets the first condition, and whether the remote repository meets the second condition. The first condition is that the current branch's working directory does not contain any uncommitted or unpushed code. The second condition is that the remote repository contains all the commit records for the current branch.
[0066] Understandably, the absence of uncommitted or unpushed code in the current branch's working directory indicates a clean working directory. A clean working directory means the code repository currently has no uncommitted changes, temporary files, or untracked files. This can be verified using commands like `git status` or `git diff`. Therefore, the first condition is crucial for selecting clean and usable copies. The remote repository contains all commit records for the current branch, meaning all commits from the local branch have been pushed to the remote repository. The commit history of this branch in the remote repository is completely consistent with the local repository, with no unpushed changes unique to the local repository. The second condition ensures that the copy used for branch switching will not result in version inconsistencies due to unpushed commits on the local repository, thus guaranteeing the safety and code consistency of branch switching.
[0067] More specifically, the second condition can be determined by using `git fetch` and `git log origin / xxx..HEAD` to see if it is met.
[0068] Step S140: Determine if the target branch exists at the far end. If it does, proceed to step S150; otherwise, proceed to step S160.
[0069] Specifically, you can use `git show-ref` or other commands to confirm whether the target branch already exists on the remote repository.
[0070] Understandably, checking if the target branch exists on the remote repository helps prevent switchover failures due to the target branch's absence, ensuring a smooth switchover process. Ensuring the target branch for local switching is synchronized with the remote repository state prevents version inconsistencies caused by operations on non-existent remote branches, and reduces code commit and merge errors due to branch information mismatches.
[0071] Step S150: Switch the current branch to the target branch.
[0072] Understandably, once it is confirmed that the target branch exists on the remote end, you can switch from the current branch to the target branch and change the current working directory to the copy directory of the target branch.
[0073] Specifically, you can use `git switch`. <branch>Switch branches.
[0074] Step S160: Switch the current branch to the preset default branch.
[0075] Specifically, you can use master (or other specified default branch) as the base for switching.
[0076] Understandably, if the target branch specified by the user does not exist on the remote endpoint, the terminal can default to the base branch (usually master or main, depending on project practices). This avoids interruptions to the switching operation due to the target branch not existing on the remote endpoint. By providing a clear switching point through a preset default branch, the branch switching process can be smoothly implemented, maintaining the continuity of automated management. At the same time, developers do not need to manually select a base branch, reducing version errors caused by confusing branch selections. Furthermore, the default branch is usually a stable version, providing a reliable baseline for subsequent development or the creation of new branches, avoiding operations based on incorrect branches.
[0077] The code branch switching method provided in this embodiment, in response to the code copy switching command of the target branch, traverses all copies of the code repository to determine if a copy exists on the target branch. If not, and if the current branch meets a first condition and the remote repository meets a second condition, then if the target branch exists on the remote repository, the current branch is switched to the target branch. The first condition is that there is no uncommitted or unpushed code in the current branch's working directory, and the second condition is that the remote repository contains all code commit records of the current branch. If the target branch does not exist on the remote repository, the current branch is switched to a preset default branch. Therefore, when a branch needs to be switched, the method automatically determines how to switch branches, preventing developers from switching branches without committing code, reducing manual operation errors, and improving development accuracy.
[0078] Furthermore, the code branch switching scheme can serve as an enhancement mechanism for Git workflows without relying on modifying Git's core logic or introducing complex toolchains. It boasts excellent portability and compatibility, making it suitable for embedding into existing CI / CD systems, development IDEs, or build systems, facilitating widespread adoption.
[0079] Considering the possibility that the current branch may not meet the first condition or the remote repository may not meet the second condition, the code branch switching scheme provided in this application may include another implementation method, such as... Figure 2 As shown, the solution may include:
[0080] Step S210: In response to the code copy switching instruction of the target branch, traverse all copies of the code repository.
[0081] Step S220: Determine if there is a copy in the target branch. If not, proceed to step S230.
[0082] Step S230: Determine whether the first condition and the second condition are met simultaneously. If yes, proceed to step S240; otherwise, proceed to step S270.
[0083] Step S240: Determine if the target branch exists at the far end. If it does, proceed to step S250; otherwise, proceed to step S260.
[0084] Step S250: Switch the current branch to the target branch.
[0085] Step S260: Switch the current branch to the preset default branch.
[0086] Specifically, steps S210-S260 correspond one-to-one with steps S110-S160 in the aforementioned embodiments, as detailed in the aforementioned embodiments, and will not be repeated here.
[0087] Step S270: Create a new copy and switch the current working directory to the directory of the new copy.
[0088] Understandably, when a replica contains uncommitted changes or the remote repository does not contain all commit records, instead of directly reusing the replica, a new replica is created. This prevents existing unfinished work from being disrupted by branch switching operations, ensuring the integrity of the original development content and reducing version chaos or operational errors caused by abnormal replica status. As a fallback mechanism in branch switching decisions, it automatically completes the creation of a new replica and directory switching without manual judgment or intervention, ensuring that the branch switching mechanism can execute according to rules in various scenarios, improving the automation and stability of multi-replica management.
[0089] Step S280: Using the branch where the new copy is located as the target branch, return to execute step S240.
[0090] Understandably, after a new copy is created, other developers may have already developed part of the code for the branch where the new copy is located and pushed it to the remote repository. Therefore, it is necessary to retrieve the code from the remote repository again to determine whether the target branch already exists.
[0091] The code branch switching method provided in this embodiment automatically determines whether to reuse the existing copy, prompt for a commit, or create a new branch copy during branch switching, based on factors such as whether a clean, usable copy exists locally, whether the current branch has been modified, and whether the remote state has been synchronized. This decision-making logic achieves intelligent and automated branch switching, significantly improving the efficiency and security of multi-task parallel development.
[0092] In some embodiments of this application, the process of creating a new copy as mentioned in the above embodiments is described, such as... Figure 3 As shown, the process may specifically include:
[0093] Step S271: Create an empty copy of the project.
[0094] Specifically, each project copy within the code repository can be named according to a naming convention (such as project-1, project-2, ..., project-N). Therefore, it's possible to iterate through all existing project copies and determine the maximum possible name for each copy. The "maximum value" in the maximum name can represent the ordinal number in the name, such as naming the maximum value as "project-9" in "project-1, project-2, ..., project-9".
[0095] Furthermore, an empty copy of the project can be created by naming it based on the maximum value.
[0096] Specifically, empty project copies can be named in increments of 1 from the maximum value.
[0097] For example, if the current working copy is named "project-9", which is also the maximum name for all project copies in the code repository, then an empty project copy could be named "project-10".
[0098] Step S272: Copy the working code from the current working directory to the project copy.
[0099] Step S273: In the directory of the project copy, clear the intermediate artifacts generated during the copying of the working code to the project copy to obtain a new copy.
[0100] Specifically, you can use the `git clean -xfd` command to clean up all possible intermediate products.
[0101] Understandably, during code copying, intermediate artifacts such as temporary files, binary files, and cached content may be generated. These intermediate artifacts are not included in Git version control, and they may be incompatible with the development environments of other branches. By clearing these intermediate artifacts, we ensure that the new copy is clean.
[0102] In some embodiments, a copy may be found under the target branch. Based on this, the code branch switching scheme provided in this application may include another implementation method, such as... Figure 4 As shown, the solution may include:
[0103] Step S310: In response to the code copy switching instruction of the target branch, traverse all copies of the code repository.
[0104] Step S320: Determine if there is a copy in the target branch. If not, proceed to step S330; if yes, proceed to step S390.
[0105] Step S330: Determine whether the first condition and the second condition are met simultaneously. If yes, proceed to step S340; otherwise, proceed to step S370.
[0106] Step S340: Determine if the target branch exists at the remote end. If it does, proceed to step S350; otherwise, proceed to step S360.
[0107] Step S350: Switch the current branch to the target branch.
[0108] Step S360: Switch the current branch to the preset default branch.
[0109] Step S370: Create a new copy and switch the current working directory to the directory of the new copy.
[0110] Step S380: Using the branch where the new copy is located as the target branch, return to execute step S340.
[0111] Specifically, steps S310-S380 correspond one-to-one with steps S210-S280 in the aforementioned embodiments, as detailed in the aforementioned embodiments, and will not be repeated here.
[0112] Step S390: Switch the current working directory to the target copy's directory.
[0113] Specifically, if a copy (the target copy) is currently on the target branch, you can directly switch your current working directory to the target copy's directory. This completes the code branch switching process.
[0114] The apparatus for implementing code branch switching provided in the embodiments of this application will be described below. The apparatus for implementing code branch switching described below can be referred to in correspondence with the method for implementing code branch switching described above.
[0115] See Figure 5 , Figure 5 This is a schematic diagram of a device structure for implementing code branch switching, as disclosed in an embodiment of this application.
[0116] like Figure 5 As shown, the device may include:
[0117] The target branch replica determination unit 11 is used to respond to the code replica switching instruction of the target branch, traverse all replicas of the code repository, determine whether there is a replica in the target branch, and if not, execute the target branch switching unit;
[0118] The first target branch switching unit 12 is used to switch the current branch to the target branch when the current branch meets the first condition and the remote end of the code repository meets the second condition, if the target branch exists on the remote end. The first condition is that there is no uncommitted or unpushed code in the working area of the current branch, and the second condition is that the remote end contains all the code commit records of the current branch.
[0119] The first default branch switching unit 13 is used to switch the current branch to a preset default branch if the target branch does not exist at the far end.
[0120] Optionally, the device may also include:
[0121] The new copy creation unit is used to create a new copy and switch the current working directory to the directory of the new copy if the current branch does not meet the first condition or the remote end does not meet the second condition.
[0122] The remote branch existence determination unit is used to determine whether the branch where the new copy is located exists in the remote branch. If it does, the second target branch switching unit is executed; otherwise, the second default branch switching unit is executed.
[0123] The second target branch switching unit is used to switch the current branch to the target branch;
[0124] The second default branch switching unit is used to switch the current branch to the preset default branch.
[0125] Optionally, the new copy creation unit includes:
[0126] An empty copy creation unit is used to create an empty project copy if the current branch does not meet the first condition or the remote end does not meet the second condition.
[0127] The code copying unit is used to copy the working code in the current working directory to the project copy;
[0128] An intermediate product removal unit is used to remove intermediate products generated during the copying of the working code to the project copy in the project copy's directory, thereby obtaining a new copy.
[0129] Optionally, the empty copy creation unit includes:
[0130] The maximum value naming determination unit is used to traverse all existing project copies and determine the maximum value name for each project copy.
[0131] An empty copy naming creation unit is used to create an empty project copy based on the maximum value.
[0132] Optionally, the device may also include:
[0133] The direct switching unit is used to switch the current working directory to the directory of the target copy if a target copy exists in the target branch.
[0134] The code branch switching device provided in this application embodiment can be applied to code branch switching devices, such as terminals: mobile phones, computers, etc. Optionally, Figure 6 The hardware structure block diagram of the code branch switching device is shown, referencing... Figure 6 The hardware structure of a code branch switching device may include: at least one processor 1, at least one communication interface 2, at least one memory 3, and at least one communication bus 4;
[0135] In this embodiment of the application, the number of processor 1, communication interface 2, memory 3, and communication bus 4 is at least one, and processor 1, communication interface 2, and memory 3 communicate with each other through communication bus 4;
[0136] Processor 1 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present invention.
[0137] Memory 3 may include high-speed RAM, and may also include non-volatile memory, such as at least one disk storage device;
[0138] The memory stores a program, which the processor can call. The program is used for:
[0139] In response to the code copy switching command for the target branch, traverse all copies of the code repository and determine whether there is a copy in the target branch;
[0140] If not, then if the target branch exists on the remote end of the code repository and the first condition is met in the current branch and the second condition is met in the remote end, then the current branch is switched to the target branch. The first condition is that there is no uncommitted or unpushed code in the working directory of the current branch, and the second condition is that the remote end contains all the code commit records of the current branch.
[0141] If the target branch does not exist at the remote end, the current branch is switched to the preset default branch.
[0142] Optionally, the refined and extended functions of the program can be found in the description above.
[0143] This application embodiment also provides a storage medium that can store a program suitable for execution by a processor, the program being used for:
[0144] In response to the code copy switching command for the target branch, traverse all copies of the code repository and determine whether there is a copy in the target branch;
[0145] If not, then if the target branch exists on the remote end of the code repository and the first condition is met in the current branch and the second condition is met in the remote end, then the current branch is switched to the target branch. The first condition is that there is no uncommitted or unpushed code in the working directory of the current branch, and the second condition is that the remote end contains all the code commit records of the current branch.
[0146] If the target branch does not exist at the remote end, the current branch is switched to the preset default branch.
[0147] Optionally, the refined and extended functions of the program can be found in the description above.
[0148] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0149] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referred to each other.
[0150] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.< / branch>
Claims
1. A code branch switching method, characterized in that, include: In response to the code copy switching command for the target branch, traverse all copies of the code repository and determine whether there is a copy in the target branch; If not, then if the target branch exists on the remote end of the code repository and the first condition is met in the current branch and the second condition is met in the remote end, then the current branch is switched to the target branch. The first condition is that there is no uncommitted or unpushed code in the working directory of the current branch, and the second condition is that the remote end contains all the code commit records of the current branch. If the target branch does not exist at the remote end, the current branch is switched to the preset default branch.
2. The method according to claim 1, characterized in that, Also includes: If the current branch does not meet the first condition or the remote end does not meet the second condition, a new copy is created and the current working directory is switched to the directory of the new copy; Determine whether the branch containing the new copy exists at the far end; If so, switch the current branch to the target branch; If not, the current branch will be switched to the preset default branch.
3. The method according to claim 2, characterized in that, The creation of a new copy includes: Create an empty copy of the project; Copy the working code from the current working directory to the project copy; In the directory of the project copy, clear the intermediate artifacts generated during the copying of the working code to the project copy to obtain a new copy.
4. The method according to claim 3, characterized in that, The creation of an empty project copy includes: Iterate through all existing project copies and determine the maximum name for each project copy; Name the project based on the maximum value and create an empty copy.
5. The method according to any one of claims 1-4, characterized in that, Also includes: If a target copy exists in the target branch, then switch the current working directory to the directory of the target copy.
6. A code branch switching device, characterized in that, include: The target branch replica determination unit is used to respond to the code replica switching instruction of the target branch, traverse all replicas of the code repository, determine whether there is a replica in the target branch, and if not, execute the target branch switching unit; The first target branch switching unit is used to switch the current branch to the target branch when the current branch meets the first condition and the remote end of the code repository meets the second condition, and if the target branch exists on the remote end. The first condition is that there is no uncommitted or unpushed code in the working directory of the current branch, and the second condition is that the remote end contains all the code commit records of the current branch. The first default branch switching unit is used to switch the current branch to the preset default branch if the target branch does not exist at the far end.
7. The apparatus according to claim 6, characterized in that, Also includes: The new copy creation unit is used to create a new copy and switch the current working directory to the directory of the new copy if the current branch does not meet the first condition or the remote end does not meet the second condition. The remote branch existence determination unit is used to determine whether the branch where the new copy is located exists in the remote branch. If it does, the second target branch switching unit is executed; otherwise, the second default branch switching unit is executed. The second target branch switching unit is used to switch the current branch to the target branch; The second default branch switching unit is used to switch the current branch to the preset default branch.
8. The apparatus according to claim 7, characterized in that, The new copy creation unit includes: An empty copy creation unit is used to create an empty project copy if the current branch does not meet the first condition or the remote end does not meet the second condition. The code copying unit is used to copy the working code in the current working directory to the project copy; An intermediate product removal unit is used to remove intermediate products generated during the copying of the working code to the project copy in the project copy's directory, thereby obtaining a new copy.
9. A code branch switching device, characterized in that, Including memory and processor; The memory is used to store programs; The processor is configured to execute the program and implement each step of the code branch switching method as described in any one of claims 1-5.
10. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the code branch switching method as described in any one of claims 1-5.