文檔協(xié)作工具 GitHub 用法大全

GitHub 基本概念

GitHub是一個面向開源及私有軟件項(xiàng)目的托管平臺狈涮,可作為開源代碼庫以及版本控制系颤介〉基本概念有:

Issue:This is a work item (RTC-lingo), or a ticket (support lingo). An issue is required for doc work or major decisions.

Branch: Basically a copy of the doc where you apply the changes. Branches named master or branch_prod are set as the branches that are published at GA or for a refresh. (See the properties files to understand how branches are published. These are the final copies, and your branch off of those branches is your workspace. You never update the main production branches without a pull request.

For example, if I want to work on 1.2, I need to check out 1.2_prod, run git pull to get the latest changes that were committed by the team, then checkout my own branch from prod. If you do not run git pull before you check out your branch, you don’t have the most recent copy of the branch.

Pull request: Since you opened your own branch, <my-branch>, against the production branch, you must create a pull request to get your changes into the main branch <_stage>. (Really, think of it as a PUSH request.)

Commit: Used as a verb, or noun. When you check in your changes, you are “committing” to your branch. A “commit” is your change. Think: Checking in code.

Repository: Everything–the code, the branches, the history…all takes place in the repo. The repo is not the branch, but the repo contains all the branches.

Clone: When you are ready to start, you first have to clone the repo. You should only do this once at the beginning, then you always have the repo, you just check out the branches you need. Cloning pulls the copy of the staging branch to your machine.

GitHub 基本流程

1. Clone your repo files to your local computer.

Context: Here you are downloading the repository files to your local computer.??

Steps:

a. Open your GitHub repository in GitHub webpage and click Clone or download. ?

b. A Launch Application window might appear asking you if you want to open in github desktop.exe, select Remember my choice and click Open link. ?

c. Click Open in Desktop. ?

d. In GitHub Desktop, observe the current repository and current branch.

2. Create a branch for your work in GitHub Desktop.

Context: Here you are taking a copy of the current repo – you will work on this copy and then merge it back into the current repo. You are also publishing your copy of the repo so that it is available for others to work on.?

Steps:

a. In GitHub Desktop, click the arrow next to Current branch.?

b. Click New branch. ?

c. Enter a name for the branch – it is best practice to give it a name that’s not easily confused with the default branch in your repository, for example, myname_active_branch.?

d. Click on Create new branch. You should see that it is creating a branch based on the default branch. ?

e. Click Create branch.?

f . Click Publish Branch

Result: You should now be able to see your branch in GitHub Desktop and GitHub webpage.

3. Edit a file.?

Context: Here you edit your file in Visual Studio, commit to your local branch and then push to github.?

a. In Github Desktop, click Open in Visual Studio Code.?

b. Navigate to the file/s you want to edit in Visual Studio Code and edit the file/s directly.?

c.? Click Save. ?

d. Once you click Save you will see that in Github Desktop, the Commit to your_branch button becomes available. Click Commit to your_branch. ?

e. Click Push origin.?

Result: You should now be able to go to the repo, select your branch and see that your edit is completed in your branch.

4. Create a pull request and merge your content.

Context: Next you want to create a pull request to get your content reviewed. There are 2 different ways of doing this.?

a. In Github desktop, with your current branch where you made your changes selected, click Create Pull Request.

b. In the Open a pull request, ensure:?

- the pull request is going from your branch to the default branch.

- the file/s you edited are listed.

- reviewers are suggested, especially those topics owned by many people. For example, toc or conref files.

5. Although GitHub Desktop is easier to use, sometimes it's still needed to use Git Bash (CLI).

a. You need to use git pull origin <default_branch_name> to pull latest changes of the default repo to your local working branch.? <default_branch_name> here means the branch that is used to publish to KC.

In this way, you can ensure you work on the latest repo and the changes of other colleagues are not overwritten.

Best practice is: Before your start your document work everyday, run git pull origin <default_branch_name> first. This can help to decrease the conflict when merging to the default branch.

b. Sometimes you may have conflicts between your custom branch and the default branch and you don't know how to handle.

An easy way is: first save the changed file to another file. Then remove the custom branch by the following commands. Create a new custom branch from GitHub Desktop, and run git pull origin <default_branch_name> to get a newest version of the default branch. At last, re-edit the file based on the changed file contents.

delete the local branch:git branch -d <your_custom_branch-name>

delete the remote branch in githubgit push origin --delete <your_custom_branch-name>

c. Other commands:

Running the command to enter your branch.?

git checkout <your own branch>

Creating a branch:?

git checkout -b <branch name>

Publishing a branch to the remote Github repository:?

git push -u origin <branch name>

Seeing a list of branches:?

git branch -l

Switching to a different branch:?

git checkout <branch name>

Creating a branch:?

git checkout -b <branch name>

Publishing a branch to the remote Github repository:?

git push -u origin <branch name>

Seeing a list of branches:?

git branch -l

Switching to a different branch:?

git checkout <branch name>

Deleting a branch:?

git branch <branch name> -d

Cloning the docs repo:

?git clone git@<repo_name>

Committing changes:

git add .

git commit -m "Issue 1 #xxxx - I changed lots of stuff"

git cherry-pick [commit_ID]. See https://stackoverflow.com/questions/9339429/what-does-cherry-picking-a-commit-with-git-mean

Pushing content:

?git push

?git push --set-upstream origin [branch]

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末帝雇,一起剝皮案震驚了整個濱河市聋伦,隨后出現(xiàn)的幾起案子夫偶,更是在濱河造成了極大的恐慌,老刑警劉巖觉增,帶你破解...
    沈念sama閱讀 206,126評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件兵拢,死亡現(xiàn)場離奇詭異,居然都是意外死亡逾礁,警方通過查閱死者的電腦和手機(jī)说铃,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,254評論 2 382
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人腻扇,你說我怎么就攤上這事债热。” “怎么了幼苛?”我有些...
    開封第一講書人閱讀 152,445評論 0 341
  • 文/不壞的土叔 我叫張陵窒篱,是天一觀的道長。 經(jīng)常有香客問我舶沿,道長墙杯,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,185評論 1 278
  • 正文 為了忘掉前任暑椰,我火速辦了婚禮霍转,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘一汽。我一直安慰自己避消,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,178評論 5 371
  • 文/花漫 我一把揭開白布召夹。 她就那樣靜靜地躺著岩喷,像睡著了一般。 火紅的嫁衣襯著肌膚如雪监憎。 梳的紋絲不亂的頭發(fā)上纱意,一...
    開封第一講書人閱讀 48,970評論 1 284
  • 那天,我揣著相機(jī)與錄音鲸阔,去河邊找鬼偷霉。 笑死,一個胖子當(dāng)著我的面吹牛褐筛,可吹牛的內(nèi)容都是我干的类少。 我是一名探鬼主播,決...
    沈念sama閱讀 38,276評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼渔扎,長吁一口氣:“原來是場噩夢啊……” “哼硫狞!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起晃痴,我...
    開封第一講書人閱讀 36,927評論 0 259
  • 序言:老撾萬榮一對情侶失蹤残吩,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后倘核,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體泣侮,經(jīng)...
    沈念sama閱讀 43,400評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,883評論 2 323
  • 正文 我和宋清朗相戀三年紧唱,在試婚紗的時候發(fā)現(xiàn)自己被綠了旁瘫。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片祖凫。...
    茶點(diǎn)故事閱讀 37,997評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖酬凳,靈堂內(nèi)的尸體忽然破棺而出惠况,到底是詐尸還是另有隱情,我是刑警寧澤宁仔,帶...
    沈念sama閱讀 33,646評論 4 322
  • 正文 年R本政府宣布稠屠,位于F島的核電站,受9級特大地震影響翎苫,放射性物質(zhì)發(fā)生泄漏权埠。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,213評論 3 307
  • 文/蒙蒙 一煎谍、第九天 我趴在偏房一處隱蔽的房頂上張望攘蔽。 院中可真熱鬧,春花似錦呐粘、人聲如沸满俗。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,204評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽唆垃。三九已至,卻和暖如春痘儡,著一層夾襖步出監(jiān)牢的瞬間辕万,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,423評論 1 260
  • 我被黑心中介騙來泰國打工沉删, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留渐尿,地道東北人。 一個月前我還...
    沈念sama閱讀 45,423評論 2 352
  • 正文 我出身青樓矾瑰,卻偏偏與公主長得像砖茸,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子脯倚,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,722評論 2 345

推薦閱讀更多精彩內(nèi)容