“This is the 9th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”
Git is an open source distributed version control system designed to handle any project, small or large, with agility and efficiency. Git is the most advanced distributed version control system in the world.
Git installation
You can use Git GUI or GITK if you want to install It from TortoiseGit on Windows. You can go to the Git website to download the corresponding version and check out the installation tutorial online.
Git Basic Configuration
Git config you can configure git parameters by using git config –list. –system, –global, and –local indicate all users (local system), current users (global), and local configurations (current directory) respectively. –local is used by default.
Creating a Git repository
You can initialize the current directory by calling Git init directly, that is, creating a Git repository.
Common commands
Git clone, Git push, Git add, Git commit, Git checkout, Git pull
Git consists of workspaces, staging areas, local repositories, and remote repositories.
- Git clone: Clone a remote repository
git clone
. - Where we normally edit code can be understood as a workspace.
- Git add ‘filename’ to the staging area after editing.
- Git commit -m ‘commit comment’ commit to local repository;
- If your workspace code is missing, you can go to your local repository and retrieve the git checkout’ file name ‘.
- The local repository submits the remote repository using git push ‘filename’.
Remote warehouse
You can use Git Remote to view the current remote library. Git remote -v displays the corresponding clone address. (Useful for multiple remote warehouses)
Adding a remote repository
Git remote add [short_name] [url] You can add a remote repository.
Fetching data from a remote repository
Git fetch [remote-name] can fetch data from a remote repository locally. You can also use Git pull
Push data to remote repository
Git push [remote_name] [branch_name] uses origin and master by default.
View remote warehouse information
git remote show origin
Delete and rename remote repositories
git remote rename [old_name] [new_name]
git remote rm [remote_name]
Git branch
Git branches are lightweight, fast, and only record index information.
Show all branches
Use Git branch to display all current branches. You can use –merged and –no-merged to view merged and unmerged branches.
Create and switch branches
Git checkout -b testing is equivalent to git checkout -b testing
$git branch testing $git checkout testingCopy the code
Caution When switching branches, ensure that there are no uncommitted changes in the working directory. Git encourages the use of branches, and you can merge branches once you’re done.
Branch merge
To merge the Hotfix branch to the master branch, use the following command:
$ git checkout master
$ git merge hotfix
Copy the code
After the merge, you can use git branch -d hotfix to delete branches. If conflicts exist during the merge, you need to manually modify them.