Git 代码管理常用命令

Git 代码管理常用命令

克隆远程仓库

➜  Gogs git clone http://192.168.100.14:3000/dengrixiao/git-test.git
Cloning into 'git-test'...
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (5/5), done.

进入仓库:

➜  Gogs cd git-test

查看远程仓库:

➜  git-test git:(master) git remote -v
origin  http://192.168.100.14:3000/dengrixiao/git-test.git (fetch)
origin  http://192.168.100.14:3000/dengrixiao/git-test.git (push)

添加远程仓库

➜  git-test git:(master) git remote add java http://192.168.100.14:3000/admini/java-framework.git
➜  git-test git:(master) git remote -v
java    http://192.168.100.14:3000/admini/java-framework.git (fetch)
java    http://192.168.100.14:3000/admini/java-framework.git (push)
origin  http://192.168.100.14:3000/dengrixiao/git-test.git (fetch)
origin  http://192.168.100.14:3000/dengrixiao/git-test.git (push)

删除远程仓库

git-test git:(master) git remote rm java

查看本地分支

➜  git-test git:(master) git branch
* master

查看远程分支

➜  git-test git:(master) git branch -r
  origin/HEAD -> origin/master
  origin/master

创建本地分支

创建新分支并立即切换到新分支

➜  git-test git:(master) git checkout -b devlop
Switched to a new branch 'devlop'

查看本地分支

➜  git-test git:(devlop) git branch
* devlop
  master

切换分支到 master

➜  git-test git:(devlop) git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
➜  git-test git:(master) git branch
  devlop
* master

合并 devlop 分支到当前分支

➜  git-test git:(master) git merge devlop
Already up to date.

推送合并结果到远程

本地分支push到远程

➜  git-test git:(devlop) git push origin devlop
Total 0 (delta 0), reused 0 (delta 0)
To http://192.168.100.14:3000/admini/git-test
 * [new branch]      devlop -> devlop

查看远程分支

➜  git-test git:(devlop) git branch -r
  origin/HEAD -> origin/master
  origin/devlop
  origin/master

本地切换分支

➜  git-test git:(devlop) git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
➜  git-test git:(master)

删除本地分支

  • -d 选项只能删除已经参与了合并的分支,对于未有合并的分支是无法删除的。

  • -D 强制删除一个分支。

➜  git-test git:(master) git branch -d devlop
Deleted branch devlop (was d9806bf).

仓库 tag 操作

查看所有 tag

➜  git-test git:(master) git tag

创建 tag

➜  git-test git:(master) git tag v1.0.0

删除本地 tag

➜  git-test git:(master) gti tag -d v1.0.0
Deleted tag 'v1.0.0' (was 03f5966)

tag 迁出 branch

➜  git-test git:(master) git checkout v1.0.0
Note: checking out 'v1.0.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 03f5966... Initial commit

➜  git-test git:(03f5966) git branch
* (HEAD detached at v1.0.0)
  devlop
  master

推送所有tag

➜  git-test git:(03f5966) git push origin --tags
Total 0 (delta 0), reused 0 (delta 0)
To http://192.168.100.14:3000/dengrixiao/git-test.git
 * [new tag]         v1.0.0 -> v1.0.0

猜你喜欢

转载自blog.csdn.net/jeikerxiao/article/details/80953293