Git tutorial notes organization (summary sharing)
This article brings you relevant knowledge about Git, mainly the compilation of git tutorial notes, including version controller methods, installation, basic operations and operating instructions, etc. I hope Helpful to everyone.
Recommended study: "Git Tutorial"
1. Version Controller Method
1.1 Actual scenario
Backup code restoration collaborative development traceability code issues
1.2 Version control method
-
Centralized version Control tools SVN and CVS
Everyone downloads the code from the central server, and submits the modifications to the central server. -
Distributed version control tool git
Everyone’s computer has a complete library, and each other can see each other’s changes.
- Explanation:
- · Git GUI: The graphical interface tool provided by Git
· Git Bash: Git The command line tool provided
After installation, set up the email first (the email identifies different people): - Open Git Bash—
Set the person
git config --global user.name "name "—
Set up email
git config --global user.email "email" can be viewed through - git config --global user.name
Whether the setting is successful
3.1 Create a local warehouse
1) Create an empty directory as a local Git warehouse 2) Enter this directory and right-click to open the Git bash window
3) Execute the command
git init 4) After the creation is successful, you can see the hidden .git directory under the folder
You can view the basic operations of
Part 4 later
3.2 Branches
Almost all version controls support branches. Everyone has an independent branch, and development does not affect each other. When finished, merge them together. HEAD points to the current branch, and modifications will only change the contents of the current branch.
git branch View branch
git branch nameCreate name branch
git checkout branch name Switch branch
git checkout -b Branch name Create and switch
git merge Branch name 1 Merge branch Branch 1 merges with the current branch
If
different branches conflict: they will not be merged automatically , storing different versions of information in files requires manual selection
git branch -d nameDelete name branch
-DForce deletion
3.3 Git remote Warehouse
Commonly used are GitHub, Code Cloud, and GitLab (commonly used by enterprises). The course uses Code Cloud as an example. 1) Open the gitee web page to log in - create a new warehouse -
2) Configure the SSH public key:
- Enter
- ssh-keygen -t rsa
in bash (continuous Press Enter to automatically overwrite if the public key already exists)
- cat ~/.ssh/id_rsa.pub
Get the public key - copy the output public key - open gitee's user-settings-SSH Public key
Verify whether the configuration is successful: - ssh -T git@gitee.com
- Open the warehouse created on gitee and copy SSH (the address of the remote warehouse)
- In bash
- git remote add name (the name you set) ssh address
Note that you need to
before this git init Check whether the configuration is successful - git remote
It will be successful if the name you set appears
Local code upload - git push [local branch name] :[Remote branch name]
Note that you must submit it in the local warehouse before doing this
The complete code is
git push [-f] [--set-upstream][Remote name] [Local branch name]: [remote branch name][-f]: Force overwriting of remote code
[–set-upstream] means establishing an association between local and remote branches
Remote branch If the name is the same as the local
, it can be omitted: [remote branch name] If both are associated , then [local branch name] can be omitted: [remote branch name] 4) Other operations
- Clone from the remote warehouse
git clone <warehouse path> [Local path]</warehouse>
- Fetch from the remote warehouse
git fetch [remote name] [ branch name]
will capture the updates in the warehouse locally and will not merge them. If the remote name and branch name are not specified, all branches will be fetched and the current branch will be updated. If you need to merge, you needgit merge [remote name]
- pull command
git pull [remote name] [branch name]
That is, grab and merge - Resolve Merge Conflicts
After AB is cloned from the remote end, A will modify it locally and then push it to the remote end. After B modifies the same content of the same file locally and wants to pull it from the remote warehouse, there will be a merge conflict. , which is the same as the way to resolve conflicts between different local branches.
3.4 Using git in IDEA
I haven’t used idea
4. Basic operation instructions
Created before Except for the .git file, other files in the folder are our working directory. Modify files (add, delete, update) in the working directory. The status of these modifications will change as we execute Git commands git add
: Create a new file from scratch (Not tracked) or modify an existing file (not staged) Use the git add
command to save the file to the staging area. (Workspace - Staging area) git commit
: The staging area enters the warehouse and generates a commit record. (Staging area - warehouse) git commit -m "Comment content"
git status
: View the status of the working directory and staging areagit log
: View the history of commits
- –all Display all branches
- –pretty=oneline Display commit information as one line
- –abbrev-commit Make the output The commit is shorter
- -graph Display with graph
git reset --hard commitID
: Version rollback
You can use git -log or git log command to view the commitIDtouch .gitignore
Add the file name that you do not want to participate in the update, and you can no longer participate in the warehouse management
Recommended learning: "Git Learning Tutorial》
The above is the detailed content of Git tutorial notes organization (summary sharing). For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics











Steps to update git code: Check out code: git clone https://github.com/username/repo.git Get the latest changes: git fetch merge changes: git merge origin/master push changes (optional): git push origin master

To download projects locally via Git, follow these steps: Install Git. Navigate to the project directory. cloning the remote repository using the following command: git clone https://github.com/username/repository-name.git

Git code merge process: Pull the latest changes to avoid conflicts. Switch to the branch you want to merge. Initiate a merge, specifying the branch to merge. Resolve merge conflicts (if any). Staging and commit merge, providing commit message.

Resolve: When Git download speed is slow, you can take the following steps: Check the network connection and try to switch the connection method. Optimize Git configuration: Increase the POST buffer size (git config --global http.postBuffer 524288000), and reduce the low-speed limit (git config --global http.lowSpeedLimit 1000). Use a Git proxy (such as git-proxy or git-lfs-proxy). Try using a different Git client (such as Sourcetree or Github Desktop). Check for fire protection

When developing an e-commerce website, I encountered a difficult problem: How to achieve efficient search functions in large amounts of product data? Traditional database searches are inefficient and have poor user experience. After some research, I discovered the search engine Typesense and solved this problem through its official PHP client typesense/typesense-php, which greatly improved the search performance.

Git Commit is a command that records file changes to a Git repository to save a snapshot of the current state of the project. How to use it is as follows: Add changes to the temporary storage area Write a concise and informative submission message to save and exit the submission message to complete the submission optionally: Add a signature for the submission Use git log to view the submission content

How to update local Git code? Use git fetch to pull the latest changes from the remote repository. Merge remote changes to the local branch using git merge origin/<remote branch name>. Resolve conflicts arising from mergers. Use git commit -m "Merge branch <Remote branch name>" to submit merge changes and apply updates.

To delete a Git repository, follow these steps: Confirm the repository you want to delete. Local deletion of repository: Use the rm -rf command to delete its folder. Remotely delete a warehouse: Navigate to the warehouse settings, find the "Delete Warehouse" option, and confirm the operation.
