Git - github-git-cheat-sheet

GitCheatSheet_issue#2366_102019-V5

https://training.github.com/downloads/github-git-cheat-sheet.pdf

Git is the open source distributed version control system.

This cheat sheet summarizes commonly used Git command line instructions for quick reference.

Git for All Platforms

http://git-scm.com

Git distributions for Linux and POSIX systems are available on the official Git SCM web site.

Configure tooling

Configure user information for all local repositories

$ git config --global user.name "name"

Sets the name you want attached to your commit transactions

$ git config --global user.email "email address"

Sets the email you want attached to your commit transactions

$ git config --global color.ui auto

Enables helpful colorization of command line output

Branches

Branches are an important part of working with Git. Any commits you make will be made on the branch you're currently "checked out" to. Use git status to see which branch that is.

$ git branch branch-name

Creates a new branch

$ git checkout branch-name

Switches to the specified branch and updates the working directory

$ git merge branch

Combines the specified branch's history into the current branch. This is usually done in pull requests, but is an important Git operation.

$ git branch -d branch-name

Deletes the specified branch

Create repositories

When starting out with a new repository, you only need to do it once; either locally, then push to GitHub, or by cloning an existing repository.

$ git init

Turn an existing directory into a git repository

$ git clone url

Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commit

The .gitignore file

Sometimes it may be a good idea to exclude files from being tracked with Git. This is typically done in a special file named .gitignore . You can find helpful templates for .gitignore files at github.com/github/gitignore .

Synchronize changes

Synchronize your local repository with the remote repository on GitHub.com

$ git fetch

Downloads all history from the remote tracking branches

$ git merge

Combines remote tracking branch into current local branch

$ git push

Uploads all local branch commits to GitHub

$ git pull

Updates your current local working branch with all new commits from the corresponding remote branch on GitHub.

git pull is a combination of git fetch and git merge

Make changes

Browse and inspect the evolution of project files

$ git log

Lists version history for the current branch

$ git log --follow file

Lists version history for a file, including renames

$ git diff first-branch...second-branch

Shows content differences between two branches

$ git show commit

Outputs metadata and content changes of the specified commit

$ git add file

Snapshots the file in preparation for versioning

$ git commit -m "descriptive message"

Records file snapshots permanently in version history

Redo commits

Erase mistakes and craft replacement history

$ git reset commit

Undoes all commits after commit, preserving changes locally

$ git reset --hard commit

Discards all history and changes back to the specified commit

GitHub Flow

Glossary

git: an open source, distributed version-control system

GitHub: a platform for hosting and collaborating on Git repositories

commit: a Git object, a snapshot of your entire repository compressed into a SHA

branch: a lightweight movable pointer to a commit

clone: a local version of a repository, including all commits and branches

remote: a common repository on GitHub that all team member use to exchange their changes

fork: a copy of a repository on GitHub owned by a different user

pull request: a place to compare and discuss the differences introduced on a branch with reviews, comments, integrated

tests, and more

HEAD: representing your current working directory, the HEAD pointer can be moved to different branches, tags, or commits

when using git checkout

GitHub Training

services@github.com

services.github.com

相关推荐
阿里嘎多学长7 小时前
2026-07-10 GitHub 热点项目精选
开发语言·程序员·github·代码托管
莫成9 小时前
git相关命令查阅
git
ljh57464911913 小时前
git stash 和 git stash apply
git
今夕资源网13 小时前
AI声音克隆软件 CosyVoice今夕一键整合包解压即用 阿里巴巴通义实验室开源 github斩获22K星标
人工智能·github·多国语言·声音克隆·零样本语音克隆·感情·ai语音克隆
胡萝卜术16 小时前
从聊天模型到本地执行助手:Remote MCP 多工具 Agent 实战
面试·架构·github
慕容引刀18 小时前
告别Commit信息纠结:使用Git AI Commit插件实现规范化提交
人工智能·git·github·visual studio code·visual studio
GoGeekBaird1 天前
我开源了 BeeWeave,给 AI Agent 搭一个越用越懂你的知识创作台
后端·github
fthux1 天前
GitZip Pro 源码解析:一个 GitHub 文件/文件夹下载扩展是如何工作的(一)整体架构与扩展入口
人工智能·ai·开源·github·open source
第一程序员1 天前
Rust Agent 子进程执行:Command 之前,先定义输入和超时
python·rust·github
2501_936960361 天前
GitHub初步了解
github