branch

Many developers who use Git prefer to work this way, such as keeping only fully stable code on the Master branch — possibly only code that has been released or will be released soon. They also have parallel branches called Develop or Next that can be used for subsequent development or stability testing — these branches don’t have to be absolutely stable, but once they are, they can be merged into the Master branch. This way, after ensuring that these completed subject branches (short term branches) pass all the tests and don’t introduce any more bugs, they can be merged into the main trunk and wait for the next release.

<! Git branch name <! Git checkout name <! Git commit -a -m '<! Git merge name <! Git status <! Git commit git push origin dev <! Git fetch origin branch.name <! Git status git commit -a -m '<! Git push origin -d branch. Name <! Git remote update origin -- git remote update origin --pruneCopy the code

The child module

Submodules allow you to use one Git repository as a subdirectory of another Git repository. It allows you to clone another repository into your own project while keeping the commit independent.

Submodule creation

Add an existing Git repository as a submodule of the working repository. You can add a new submodule by following the Git submodule add command with the relative or absolute URL of the project you want to track. By default, submodules put subprojects in a directory with the same name as the repository, but if you want to put them somewhere else, you can add a different path at the end of the command.

git submodule add url path<! Git config -f. Gitmodules submodule git config -f. Gitmodules submodule Submodule name Branch BranchCopy the code

Clone the submodule project

When you clone a project that contains submodules, the submodule directory is included by default, but there are no files in it yet. You must run two commands: git submodule init to initialize the local configuration file, and Git subModule update to grab all data from the project and check out the appropriate commits listed in the parent project.

git clone url pathGit submodule update git submodule update --init --recursiveCopy the code

But there’s an easier way. If you pass the –recurse-submodules option to the Git clone command, it automatically initializes and updates every submodule in the repository, including any nested submodules that might exist.

git clone --recurse-submodules url path
Copy the code

Sets the configuration information related to submodules

<! Git config --global diff. Submodule log <! Git config status.submodulesummary -- git config status.submodulesummary1
Copy the code

Update the submodule project

Git tries to update all submodules by default, so if there are many, you can pass the name of the submodule you want to update.

git submodule update --remote
Copy the code

Submit the submodule project

Implement the submodule to submit the modified code to the submodule’s corresponding remote repository

<! -- Go to the path where the submodule resides -->cd /path/to/submodule.pathGit commit -a -m <! Git push origin HEAD:branch. Name <! -- Return to the project root directory -->cd /path<! Git commit -a -m 'git push origin branch.nameCopy the code