git 代码推送流程_Git 101:一个让您开始推送代码的Git工作流程
git 代碼推送流程
I'm going to explain Git the way I wish someone had explained to me back when I was first learning.
我將以我希望有人在我第一次學(xué)習(xí)時向我解釋的方式來解釋Git。
I'll show how you can get started with just a few commands, and the concepts at work behind those concepts.
我將展示您如何僅需幾個命令就可以開始使用,以及這些概念背后的概念。
基本概念 (Basic concepts)
您的本地代碼 (Your local code)
This is the work that you do on your computer. Any edits, formats, features or development work that you have in your computer is your local code.
這是您在計算機上所做的工作。 您在計算機中進行的任何編輯,格式,功能或開發(fā)工作都是您的本地代碼。
上演網(wǎng)站 (Staged site)
Once you are happy with the changes or amount of work done, you can mark it as ready for stage. It means that you are declaring that these lines of code are ready to be committed.
一旦對更改或完成的工作感到滿意,就可以將其標(biāo)記為準(zhǔn)備就緒。 這意味著您要聲明這些代碼行已準(zhǔn)備好提交。
服務(wù)器 (The server)
Once you are feel ready with the files you have staged, you can send them out to the server which stores all your code so that other people can use it too. Now your files can be viewed by other people and be worked on.
一旦準(zhǔn)備好暫存的文件,就可以將它們發(fā)送到存儲所有代碼的服務(wù)器,以便其他人也可以使用它。 現(xiàn)在,您的文件可以被其他人查看并進行處理。
最終目標(biāo) (The end goal)
The idea behind git is that your code on the remote server should be synced with the code on your machine. When you work with other folks, their code should be synced with your code. So if your co-workers pushed new code, you should be able to easily update your code to reflect their changes.
git的想法是,應(yīng)該將遠程服務(wù)器上的代碼與計算機上的代碼同步。 當(dāng)您與其他人一起工作時,他們的代碼應(yīng)與您的代碼同步。 因此,如果您的同事推送了新代碼,則您應(yīng)該能夠輕松地更新代碼以反映他們的更改。
The end of goal is that everything on the server should be the same as everything on your local machine. You should send files to the server as soon as possible so that when others view your code, they have the most updated version.
目標(biāo)的最后是服務(wù)器上的所有內(nèi)容都應(yīng)與本地計算機上的所有內(nèi)容相同。 您應(yīng)該盡快將文件發(fā)送到服務(wù)器,以便其他人查看您的代碼時,它們具有最新版本。
工作流程 (Workflow)
Let’s say you have a folder on your computer where you have your code. You want to put it in GitHub so you can version control it.
假設(shè)您在計算機上有一個存放代碼的文件夾。 您希望將其放在GitHub中,以便可以對其進行版本控制。
Here’s how you can do it.
這是您的操作方法。
1.獲取存儲庫。 (1. Getting a repository.)
There’s two ways of getting a repository?—?either you can create one of your own, or you can work off of someone’s repository and contribute to their repository. Which one you choose depends on the project you are working on. If you are working on a project by yourself, you are more likely to create a repository from scratch and start writing code. When you work on open source code or working in a team, you will most likely get a repository that already exists. Let’s talk about how to do both?—
獲取存儲庫有兩種方法-您可以創(chuàng)建自己的存儲庫,也可以在某人的存儲庫中工作并為他們的存儲庫做出貢獻。 選擇哪一個取決于您正在處理的項目。 如果您是一個人從事項目,則更有可能從頭開始創(chuàng)建存儲庫并開始編寫代碼。 當(dāng)您使用開源代碼或團隊合作時,很可能會獲得一個已經(jīng)存在的存儲庫。 讓我們來談?wù)剝烧叩淖龇?
創(chuàng)建一個倉庫 (Create a Repository)
First you will need to create a GitHub account if you don’t already have one. Click on Repositories tab and click “New”
首先,如果您還沒有一個GitHub帳戶,則需要創(chuàng)建一個。 單擊存儲庫選項卡,然后單擊“新建”
Follow instructions to create your new repository. Let’s say we name this repository test-repo . Once you have created this repo, GitHub gives instruction on how to set it up on your local computer.
按照說明創(chuàng)建新的存儲庫。 假設(shè)我們將此存儲庫命名為test-repo 。 創(chuàng)建此存儲庫后,GitHub會提供有關(guān)如何在本地計算機上進行設(shè)置的說明。
Use the instructions to create a new repository on the command line -
使用說明在命令行上創(chuàng)建新的存儲庫-
克隆存儲庫 (Cloning a repository)
git clone <repository>
git clone <repository>
Let’s say you want to get the code I am working on so you can work off of it on your computer. You will need to find my github account and clone a repository that you are interested in. Today we are going to work on this repository?—
假設(shè)您要獲取我正在使用的代碼,以便可以在計算機上使用它。 您將需要找到我的github帳戶并克隆一個您感興趣的存儲庫。今天,我們將在該存儲庫上進行工作-
git clone git@github.com:shrutikapoor08/devjoke.git
2.創(chuàng)建一個分支 (
2. Create a branch)
Creating a branch helps to keep work in progress separate from a working piece of code. It also helps you modularize your code and keep features separate while you are still working on them. Let’s make a new branch joke-branch by using
創(chuàng)建分支有助于使工作與代碼段分開進行。 它還可以幫助您模塊化代碼,并在使用功能時將其分開。 讓我們通過使用一個新的分支joke-branch
git checkout -b joke-branch
git checkout -b joke-branch
You can push this branch to the server (origin)by?—
您可以通過以下方式將此分支推送到服務(wù)器( origin ):
?git push origin joke-branch
git push origin joke-branch
Now let’s assume that you and I are teammates. We are working on a project together. Let’s walk through the workflow.
現(xiàn)在,假設(shè)您和我是隊友。 我們正在共同致力于一個項目。 讓我們來看一下工作流程。
3.修改代碼 (3. Modifying code)
Once you understand what the code does, you are ready to make edits. If you are working on somebody else’s repository, it is a good idea to make a forkof their repository. “Forking” is making a copy of a repository. It is like running a repository through a copy machine and getting your own copy. You can do whatever you want to your copy, make changes, edit files, delete files or add new files. If you want, you can send your updates to the original repository and ask for your code to get merged into the original repository.
一旦了解了代碼的功能,就可以進行編輯了。 如果您正在使用其他人的存儲庫,則最好將他們的存儲庫作為fork 。 “分叉”正在復(fù)制存儲庫。 就像通過復(fù)制機運行存儲庫并獲取自己的副本一樣。 您可以對副本執(zhí)行任何操作,進行更改,編輯文件,刪除文件或添加新文件。 如果需要,可以將更新發(fā)送到原始存儲庫,并要求您的代碼合并到原始存儲庫中。
We are going to be modifying this code by creating a fork of this repository. To fork a repository, click on the Fork button at the top of the repository.
我們將通過創(chuàng)建此存儲庫的派生來修改此代碼。 要派生存儲庫,請單擊存儲庫頂部的“分叉”按鈕。
Now if you go to your Github profile, you can see your newly created fork repository in your profile. Woot Woot!
現(xiàn)在,如果您轉(zhuǎn)到Github個人資料,則可以在個人資料中看到新創(chuàng)建的fork存儲庫。 嗚嗚!
Now we are going to make some changes. Open the README.mdfile. To this file, we are going to add a DevJoke! ?Think of a clever programming joke and add it to the top of this file. Here is a #DevJoke for you?—?
現(xiàn)在,我們將進行一些更改。 打開README.md文件。 在這個文件中,我們將添加一個DevJoke! 考慮一個聰明的編程笑話,并將其添加到此文件的頂部。 這是給您的#DevJoke-
Why do Java programmers wear glasses?
為什么Java程序員戴眼鏡?
.
。
.
。
.
。
.
。
4.提交代碼 (4. Committing code)
Now, let’s save and commit this file. If you are committing a newly created file, you will first have to add it to your stage. You can do so by?—?
現(xiàn)在,讓我們保存并提交該文件。 如果要提交新創(chuàng)建的文件,則首先必須將其添加到舞臺。 您可以通過-
git add <filename>
git add <filename>
Once your file is staged, you can commit. Be sure to append your commit with a message that will help you remember in the future what this commit is about.
暫存文件后,即可提交。 確保在提交后附加一條消息,以幫助您將來記住該提交的含義。
git commit -m "Adding DevJoke about C#
git commit -m "Adding DevJoke about C#
5.推送代碼 (5. Pushing code)
Remember, when you are working on a repository that other people are also working on, it is possible that while you were working on your local version, some people may have pushed code. So now the server is “one step ahead of you”. You now need to sync your computer to the server to make sure you have the most updated code. To do so, you can pull from the server?—
請記住,當(dāng)您在其他人也正在使用的存儲庫上工作時,當(dāng)您在本地版本上工作時,可能會有一些人推送了代碼。 因此,現(xiàn)在服務(wù)器“比您領(lǐng)先一步”。 現(xiàn)在,您需要將計算機同步到服務(wù)器,以確保您具有最新的代碼。 為此,您可以從服務(wù)器中拉出-
git pull origin <branch-name>
git pull origin <branch-name>
If you have never made a branch, don’t worry. Git gives you master branch by default. You can also make a new branch by?—
如果您從未建立過分支,請不要擔(dān)心。 Git默認為您提供master分支。 您還可以通過以下方式建立新分支:
git checkout -b <branch-name>Now that you have committed your code and your local machine is updated from server, you are ready to push your changes for the world to see. To push to branch master, you can do so by?—?git push origin master
現(xiàn)在,您已經(jīng)提交了代碼,并且本地服務(wù)器已從服務(wù)器更新,您可以將所做的更改推送給全世界。 要推送到分支master ,可以通過以下方式進行操作:git push origin master
YAYY!!! You made your first push! Give yourself a pat on the back. That was the hard part. Now you are ready to commit your ass off.
呀! 您是第一個推動者! 拍拍自己的背部。 那是困難的部分。 現(xiàn)在,您可以準(zhǔn)備放棄了。
6.發(fā)出拉取請求 (6. Making a Pull Request)
Now, send me that wonderful #DevJoke of yours by creating a pull request. Pull request is a feature by which you?—?the developer, requests me?—?the code owner to merge your code into the repository. Creating a pull request is easy. Go to github.com and open the repository you have been working on.
現(xiàn)在,通過創(chuàng)建拉取請求,將您的精彩的#DevJoke發(fā)送給我。 拉請求是一項功能,您(開發(fā)人員可以向我索取)代碼所有者將您的代碼合并到存儲庫中。 創(chuàng)建拉取請求很容易。 轉(zhuǎn)到github.com并打開您一直在使用的存儲庫。
You will see a Pull request button like this?:
您將看到如下所示的“拉取”請求按鈕:
Click the button and follow the instructions to create a pull request. Make sure your changes are correctly reflected on the “Comparing changes” screen.
單擊按鈕,然后按照說明創(chuàng)建拉取請求。 確保您的更改正確顯示在“比較更改”屏幕上。
Click on “Create pull request” and that’s it! You are done! You successfully made your first Pull request!
單擊“創(chuàng)建請求請求”,僅此而已! 大功告成! 您已成功發(fā)出第一個Pull請求!
👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏
👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏
Now, go ahead and send me that DevJoke!
現(xiàn)在,繼續(xù)發(fā)送DevJoke給我!
Did you learn something new? Have comments? Know a DevJoke? Tweet me @shrutikapoor08
你學(xué)到新東西了嗎? 有意見嗎? 知道開發(fā)笑話嗎? 鳴叫我@ shrutikapoor08
翻譯自: https://www.freecodecamp.org/news/git-101-git-workflow-to-get-you-started-pushing-code/
git 代碼推送流程
總結(jié)
以上是生活随笔為你收集整理的git 代码推送流程_Git 101:一个让您开始推送代码的Git工作流程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做梦梦到和明星在一起了是什么意思
- 下一篇: tableau可视化_如何在Tablea