TOC

Git 基础

Linus 为了托管内核代码的方便,创建了 Git。
之前,Linux 开发者使用的是 BitKeeper,不过社区对这个私有工具总是不放心,然后 BitKeeper 方面对于部分开发者试图逆向工程不满。

对于大多数公司来说, Git 的设计颇为复杂。
但是没办法,现在 Git 已经成为大多数开发者的选择。

基础命令

  • git config 配置
  • git init 初始化当前目录为 git 仓库
  • git clone 克隆一个远程仓库到本地
  • git add 添加变更(提交之前的挑选)
  • git commit 提交变更
  • git push 推送变更到远程仓库
  • git pull 拉取远程仓库变更,并合并到本地;等于 git fetch + git merge
  • git status 查看变更状态
  • git log 查看提交历史
  • git branch 分支管理
  • git checkout 切换分支
  • git fetch 拉取远程仓库变更
  • git merge 合并分支

示例

git config --global user.name "Your Name"
git config --global user.email "your@email.com"

git clone git@github.com:your-username/example
cd example

# 创建新文件
echo "hello" > newfile
git add newfile
git commit -m "Add newfile"

git push origin master

参考资料与拓展阅读

如果你有魔法,你可以看到一个评论框~