Git 是一个分布式版本控制系统,可以在本地或者远程仓库中存储代码和文件。以下是一些基本的 Git 操作:
- 在本地创建一个新的 Git 仓库:
$ mkdir my-project $ cd my-project $ git init
- 将文件添加到 Git 仓库中:
$ git add . $ git add -A
- 提交更改:
$ git commit -m "Initial commit"
- 连接到远程仓库:
$ git remote add origin https://github.com/username/my-project.git
- 将本地仓库推送到远程仓库:
$ git push -u origin master
- 拉取远程仓库的更改到本地:
$ git pull origin master
- 创建和合并分支:
$ git branch my-branch $ git checkout my-branch $ git merge origin/master
- 标记一个分支为已合并:
$ git branch -m master
- 删除一个分支:
$ git branch -D my-branch
- 查看 Git 历史记录:
$ git log