$ git clone git@github.com:hirocastest/Hello-World.git
$ git log --graph
How to understand the basic use of git in 20 minutes
This article brings you basic knowledge about the use of git, including basic operations of git, branch operations, change submission operations, etc. I hope it will be helpful to everyone.
#1. Set SSH Key
Set SSH Key so that the device can have permission to access the code warehouse in the account
$ ssh-keygen -t rsa -C "your_email@example.com"
-
"your_email@example.com"
Set it as the registered email address of your GitHub account - The id_rsa file is the private key, and id_rsa.pub is the public key.
$ cat ~/.ssh/id_rsa.pub
ssh-rsa The content of the public key your_email@example.com
- Then copy the public key and add it to the account. Pay attention to the # in front. ##ssh-rsa
Also copy it
Avatar》Settings》SSH Key》new SSH Key
$ ssh -T git@github.com Enter passphrase for key '/c/Users/MYPC/.ssh/id_rsa': Hi abc! You've successfully authenticated, but GitHub does not provide shell access.
2. Basic git operations
2.1 git clone existing warehouse$ git clone git@github.com:hirocastest/Hello-World.git
Copy after login
You will be asked to enter the open key set on GitHub. Password, after successful authentication, the warehouse will be cloned into the current directory. 2.2 git add adds the file to the staging areaAfter the code is written, add the code to the system's staging area
$ git clone git@github.com:hirocastest/Hello-World.git
$ git add 文件夹/文件
$ git commit -m "记录一行提交信息"
- m indicates an overview of this submission. If you want to record detailed information, remove -m
push command, and the warehouse on GitHub will be updated
$ git push
clone method to create a warehouse, no execution is required
init Operation. If you want to set a local file as a warehouse, you need to perform an init operation
$ mkdir git-tutorial $ cd git-tutorial $ git init
$ git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
Copy after login
The result is that we are under the master branch and there is nothing to submit Content2.7 git log View submission log
$ git status # On branch master # # Initial commit # nothing to commit (create/copy files and use "git add" to track)
git log command can view the logs submitted in previous warehouses. Including who made the commit or merge at what time
$ git log commit 5dbbff6e009abb8a6cc44187c93b694f94fbf82a (HEAD -> main, origin/main, origin/HEAD) Author: ywm <ywm_up@qq.com> Date: Sun Feb 28 17:17:00 2021 +0800
-- pretty=short after the git log
command
$ git log --pretty=short
git diff Check the difference between the current working book and the staging area
$ git diff
3. Branch operation
You can create multiple branches and perform completely different jobs at the same time. Wait for the branch job to be completed before merging it with the master branch. Through the flexible use of branches, multiple people can perform concurrent development efficiently at the same time. 3.1 git branch displays the branch listThere is an “*” (asterisk) on the left side of the master branch, indicating that this is the branch we are currently on.$ git branch * master
$ git checkout -b feature-A
$ git branch feature-A $ git checkout feature-A
$ git checkout main
$ git checkout -
- Do this: create a new branch feature, and modify the README on the new branch. md, and add and commit
$ git merge --no-ff feature
3.4 git log --graph View branches as icons
$ git log --graph
Copy after login
$ git log --graph
4. Change commit operations
4.1 git reset Backtrack historical versions
$ git reset --hard 目标时间点的hash值
Copy after login
View the operation log of the current warehouse through $ git reset --hard 目标时间点的hash值
git reflog to find the hash value before the backtracking history. As long as git's GC (garbage collection) is not performed, the recent historical status can be retrieved at will through the log. Even if the developer performs a git operation by mistake, he can basically use the git reflog command to restore to the original state.
$ git reflog
- When merging operations, conflicts are prone to occur. At this time, you need to
- open the editor to resolve the conflict In actual development, one of them often needs to be deleted, so be sure to
- carefully analyze the content of the conflicting part before making modifications. After resolving the conflict, perform add and commit operations again
$ git commit --amend
git rebase -i HEAD~2
5 推送至远程仓库
5.1 git remote add 添加远程仓库
在创建新仓库的时候,建议不要勾选 README.md 文件,这样会使本地仓库和远程仓库失去整合性。虽然到时候可以强制覆盖,但防止这一情况发生,还是不要勾选,就创建一个空仓库就好。
git remote 在先写代码,后创建仓库的情况下能较好的使用
$ git remote add origin git@github.com:github-book/git-tutorial.git
对于一般先创仓库,后写代码的,需要先 pull 下来仓库,再对文件进行修改
5.2 git push 推送至远程仓库
推送至 master 分支
$ git push -u origin master
-u 参数可以在推送的同时,将 origin 仓库的 master 分支设置为本地仓库当前分支的 upstream(上游),添加这个参数,将来运行 git pull 命令从远程仓库获取内容的时候,本地仓库的这个分支就可以直接从 origin 的 masteer 分支获取内容,省去了另外添加参数的麻烦
除了 master 分支之外,还可以推送到其他分支
$ git checkout -b feature-D $ git push -u origin feature-D
6 从远程仓库中获取
6.1 git clone 获取远程仓库
$ git clone git仓库地址
将本地的 feature-D 分支更新到最新状态
$ git pull origin feature-D
- 多名开发者在同一个分支中进行作业时,为减少冲突情况的发生,建议更频繁的进行 push 和 pull 操作
推荐学习:《Git教程》
The above is the detailed content of How to understand the basic use of git in 20 minutes. 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

AI Hentai Generator
Generate AI Hentai for free.

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

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

DeepSeekAI Tool User Guide and FAQ DeepSeek is a powerful AI intelligent tool. This article will answer some common usage questions to help you get started quickly. FAQ: The difference between different access methods: There is no difference in function between web version, App version and API calls, and App is just a wrapper for web version. The local deployment uses a distillation model, which is slightly inferior to the full version of DeepSeek-R1, but the 32-bit model theoretically has 90% full version capability. What is a tavern? SillyTavern is a front-end interface that requires calling the AI model through API or Ollama. What is breaking limit

AI tools include: Doubao, ChatGPT, Gemini, BlenderBot, etc.

Grayscale Investment: The channel for institutional investors to enter the cryptocurrency market. Grayscale Investment Company provides digital currency investment services to institutions and investors. It allows investors to indirectly participate in cryptocurrency investment through the form of trust funds. The company has launched several crypto trusts, which has attracted widespread market attention, but the impact of these funds on token prices varies significantly. This article will introduce in detail some of Grayscale's major crypto trust funds. Grayscale Major Crypto Trust Funds Available at a glance Grayscale Investment (founded by DigitalCurrencyGroup in 2013) manages a variety of crypto asset trust funds, providing institutional investors and high-net-worth individuals with compliant investment channels. Its main funds include: Zcash (ZEC), SOL,

The entry of top market maker Castle Securities into Bitcoin market maker is a symbol of the maturity of the Bitcoin market and a key step for traditional financial forces to compete for future asset pricing power. At the same time, for retail investors, it may mean the gradual weakening of their voice. On February 25, according to Bloomberg, Citadel Securities is seeking to become a liquidity provider for cryptocurrencies. The company aims to join the list of market makers on various exchanges, including exchanges operated by CoinbaseGlobal, BinanceHoldings and Crypto.com, people familiar with the matter said. Once approved by the exchange, the company initially planned to set up a market maker team outside the United States. This move is not only a sign

ElizaOSv2: Empowering AI and leading the new economy of Web3. AI is evolving from auxiliary tools to independent entities. ElizaOSv2 plays a key role in it, which gives AI the ability to manage funds and operate Web3 businesses. This article will dive into the key innovations of ElizaOSv2 and how it shapes an AI-driven future economy. AI Automation: Going to independently operate ElizaOS was originally an AI framework focusing on Web3 automation. v1 version allows AI to interact with smart contracts and blockchain data, while v2 version achieves significant performance improvements. Instead of just executing simple instructions, AI can independently manage workflows, operate business and develop financial strategies. Architecture upgrade: Enhanced A

Researchers from Shanghai Jiaotong University, Shanghai AILab and the Chinese University of Hong Kong have launched the Visual-RFT (Visual Enhancement Fine Tuning) open source project, which requires only a small amount of data to significantly improve the performance of visual language big model (LVLM). Visual-RFT cleverly combines DeepSeek-R1's rule-based reinforcement learning approach with OpenAI's reinforcement fine-tuning (RFT) paradigm, successfully extending this approach from the text field to the visual field. By designing corresponding rule rewards for tasks such as visual subcategorization and object detection, Visual-RFT overcomes the limitations of the DeepSeek-R1 method being limited to text, mathematical reasoning and other fields, providing a new way for LVLM training. Vis

Weekly Observation: Businesses Hoarding Bitcoin – A Brewing Change I often point out some overlooked market trends in weekly memos. MicroStrategy's move is a stark example. Many people may say, "MicroStrategy and MichaelSaylor are already well-known, what are you going to pay attention to?" This is true, but many investors regard it as a special case and ignore the deeper market forces behind it. This view is one-sided. In-depth research on the adoption of Bitcoin as a reserve asset in recent months shows that this is not an isolated case, but a major trend that is emerging. I predict that in the next 12-18 months, hundreds of companies will follow suit and buy large quantities of Bitcoin
