Skip to content

Commit 21c0f47

Browse files
committed
git remote and git branch rename tutorial
1 parent 2141054 commit 21c0f47

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,26 @@ git branch -d dev
421421
git branch -D dev
422422
```
423423

424+
補充,git branch 也可以修改名稱,而且 commit id 是不會改變的,使用方法也很簡單,
425+
426+
可參考 git-branch [文件](https://git-scm.com/docs/git-branch#git-branch--m),使用方法如下,
427+
428+
```text
429+
git branch -m <name>
430+
```
431+
432+
原本的 b1 branch 分支的 log 如下,
433+
434+
![alt tag](https://i.imgur.com/b1K1EUy.png)
435+
436+
現在將 b1 branch 修改成 b2 branch,
437+
438+
![alt tag](https://i.imgur.com/Twz5kRm.png)
439+
440+
如果你仔細和剛剛的 log 比較,你會發現 log 的 commit id 是不會改變的,
441+
442+
![alt tag](https://i.imgur.com/qMjqV3Z.png)
443+
424444
## 新建分支 branch 並 push
425445

426446
相信大家有時候在 github 上面都會看到,如下圖,很多分支
@@ -1473,6 +1493,8 @@ git remote -v
14731493

14741494
![alt tag](https://i.imgur.com/Qb5VHoP.png)
14751495

1496+
git remote 這個指令的更多說明可參考官方文件 [git-remote](https://git-scm.com/docs/git-remote)
1497+
14761498
接著我們使用下列指令新增一個 origin 的遠端
14771499

14781500
```cmd
@@ -1507,6 +1529,60 @@ P.S 設定檔在資料夾底下的隱藏檔 ".git" 底下,裡面有一個 conf
15071529

15081530
![alt tag](https://i.imgur.com/41xb8eu.png)
15091531

1532+
補充幾個 git remote 的指令,他也支援 rename 以及 remove ,
1533+
1534+
現在的 remote 如下,
1535+
1536+
![alt tag](https://i.imgur.com/rr9SE3g.png)
1537+
1538+
讓我們重新命名 remote,語法如下,
1539+
1540+
```text
1541+
git remote rename <old> <new>
1542+
```
1543+
1544+
```text
1545+
git remote rename origin2 origin
1546+
```
1547+
1548+
執行後,你會發現 remote 成功被修改成 origin 了,
1549+
1550+
![alt tag](https://i.imgur.com/ixP1H7Z.png)
1551+
1552+
接下來我們試試 remove,語法如下,
1553+
1554+
```text
1555+
git remote remove <name>
1556+
```
1557+
1558+
```text
1559+
git remote remove origin
1560+
```
1561+
1562+
成功刪除,現在 remote 是空的了,
1563+
1564+
![alt tag](https://i.imgur.com/OQFRWDg.png)
1565+
1566+
接下來我們嘗試新增一個 remote,指令如下,
1567+
1568+
```text
1569+
git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>
1570+
```
1571+
1572+
```cmd
1573+
git remote add origin git@github.com:blue-rubiks/t11.git
1574+
```
1575+
1576+
![alt tag](https://i.imgur.com/cKsiBBs.png)
1577+
1578+
如果我們想修改 origin 的 url,可以使用
1579+
1580+
```cmd
1581+
git remote set-url origin git@blue.github.com:blue-rubiks/t11.git
1582+
```
1583+
1584+
![alt tag](https://i.imgur.com/LJICTNM.png)
1585+
15101586
## Multiple SSH Keys settings for different github account
15111587

15121588
* [Youtube Tutorial - Multiple SSH Keys settings for different github account](https://youtu.be/gDxG-4tF7B8)

0 commit comments

Comments
 (0)