|
Size: 13577
Comment:
|
Size: 15044
Comment: add info about necessary permissions
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 1: | Line 1: |
| <<TableOfContents()>> | ## page was renamed from TechDocs/Git/Guide:Workflow <<TableOfContents(3)>> |
| Line 7: | Line 8: |
| Before you start, make sure you have everything set up as described in [[TechDocs/Git/Guide:FirstSteps]]. Also make sure you understand basic Git commands as described in [[TechDocs/Git/Guide:FirstCommit]] | Before you start, make sure you have everything set up as described in [[TechDocs/Git/FirstSteps]]. Also make sure you understand basic Git commands as described in [[TechDocs/Git/FirstCommit]]. |
| Line 9: | Line 10: |
| == The Three Repositories == | This page explains two different scenarios. 1. A [[#Simple_approach|simple approach]] with direct edits to the Git repository. It's easier to understand but bears a few risks. 1. A more [[#Complex_approach|complex approach]] which involves forks and Pull Requests. This is safer and allows more checks. For example, we highly prefer this for changes on the fsfe.org website. It will start with the simple approach which skips a lot of detailed information about the different aspects Git it built upon. If you don't understand something, please have a look into the complex approach, or skim external resources like the excellent [[https://betterexplained.com/articles/a-visual-guide-to-version-control/|Visual guide to version control]] and its following guides in the series. = Simple approach = This workflow reduces complexity by giving up the need of forks, extra branches and pull requests. While it's easier to learn, we require the complex approach for some repositories like the website because it's safer, more transparent and more reliable. Also, this method requires that you have at least write access to the repository. In this example, it is assumed you would like to work on [[https://git.fsfe.org/FSFE/share-buttons|FSFE/share-buttons]], an interesting but seldom used repository. == Basic knowledge == As with the complex workflow, you should rudimentally know about the scheme you are working with. === The Two Repositories === There are only two repositories you are working with: * The '''main remote repository''' or '''origin''': https://git.fsfe.org/FSFE/share-buttons. This is the most important repository, because everyone has agreed that this is the "official" repository. You will directly be working on that. * '''Your local repository'''. This is the directory on your local computer. You also have complete control over this repository. Nothing you do in this repository affects any other repository '''until you push'''. === Branches === Unlike with the complex approach, branching will play no role in most repositories in which the simple workflow can be used. You will only work with the '''master''' branch which is the official "timeline" of the repository. Any change that you will make and upload to this branch will directly affect the local repositories of the others working on it as soon as they update to the latest status. == One-time preparations == In the following you'll find the steps which have to be execute only once per repository you want to work on. It is assumed that you successfully [[TechDocs/Git|set up Git on your computer according to our recommendations]]. 1. Clone the repository to a place on your computer. Within a terminal, move to a location of your choice and execute `git clone git@git.fsfe.org:FSFE/share-buttons.git`. This will create a folder called ''share-buttons'' inside the directory your terminal has opened. == Workflow == After the one-time preparations, the following steps have to be execute in a terminal positioned in your local repository each time you would make an edit. 1. Before making any change, always do a `git pull`. This will update your local copy with the remote repository to get the latest changes. 1. Now you can make any changes, e.g. create new files or edit existing ones. You can do that in your file browser. 1. Run `git status` to be presented with a list of edits you have done. This can be executed any time and will help you to understand the difference between the official status and your own edits. 1. In order to share your changes, you will have to ''add'' them. This has to be done for new, modified and deleted files, and will add them to the list of files you would like to share your modifications for: `git add new_file1.txt modified_file2.jpg`. Note that this can also be directories, and that you can add multiple files at once! 1. Now let's make it official! By committing your edits, you are required to describe them in order to allow others to understand them: `git commit -m 'I did some modifications in order to solve this and that problem'`. Please be informative and concise at the same time. 1. Your local copy has been changed, now ''push'' the changes online to all other people working on the repository: `git push`. That makes it official, and you can see it online. Due to the disadvantages of this workflow, you shouldn't let pass too much time between the first and last step in order to avoid conflicts with potential edits of other people. Also, please make sure to double-check your edits since there is no check in between. = Complex approach = The complex workflow is recommended for intensively used repositories which are affected by many changes by multiple users. You will not work on the official repository directly but on your own copy ("fork") and ask a maintainer to include your changes to the official repositories in an extra step. Also, you can contribute to any public repository even if you don't have write access. This guide is also written in a more verbose form than the simple approach. even if you feel confident that you are not required to know the advanced workflow, it probably will still help you to understand Git a bit better. == Basic knowledge == === The three repositories === |
| Line 13: | Line 71: |
| * The '''main remote repository''' or '''upstream''': https://git.fsfe.org/fsfe/fsfe-website. This is the most important repository, because everyone has agreed that this the "official" repository. | * The '''main remote repository''' or '''upstream''': https://git.fsfe.org/fsfe/fsfe-website. This is the most important repository, because everyone has agreed that this is the "official" repository. |
| Line 19: | Line 77: |
| These three terms will consistently be used in this guide. | These three terms will consistently be used in this guide. However, in the simple guide, the forked '''origin''' is not used as you are directly working on the main repository. |
| Line 21: | Line 79: |
| == A note on branches == | === Branches === |
| Line 31: | Line 89: |
| = Guide: Graphical workflow = | == Workflow == |
| Line 33: | Line 91: |
| This guide is for those who want to use Git with a graphical user interface. We will use Git Cola, but the instructions here should generally translate loosely between different interfaces. | This guide is way to create a new '''pull request''', i.e. a proposal for an addition or change of yours to the '''upstream''' repository, mostly via the terminal. This solution is ''preferred'' over using graphical applications, because it is easier to ask someone to type a certain command, than it is to ask them to push some buttons. |
| Line 35: | Line 93: |
| You can find Git Cola as `git-cola` package in most distributions. | === Set up your repository === |
| Line 37: | Line 95: |
| == Set up your repository == | /!\ '''Please, keep in mind that for setting up git and cloning repository you will need from 2 to 3 hours of time! So it's better to do this when you come to the office in the morning.''' |
| Line 41: | Line 99: |
| Open Git Cola and press the "Clone" button. Insert "git@git.fsfe.org:YOURNAME/fsfe-website.git" into the URL bar and proceed. It should download the repository for you. {{attachment:clone.png}} You are now on the '''master branch''' of fsfe-website in your local repository. Also, by cloning, you have implicitly configured a "remote" for your local repository. This remote is called '''origin''', and is equal to "git@git.fsfe.org:YOURNAME/fsfe-website.git". You might want to add an extra remote, however, pointing to the main remote repository. Let's do this now, and call it '''upstream'''. Click on "File", then "Edit Remotes...". Add a new repository called upstream with the link "git@git.fsfe.org:fsfe/fsfe-website.git". {{attachment:remote.png}} Your local repository is now tracking two remote repositories, and you are ready to begin working. == Syncing all repositories == Before you start, you may want to synchronise all repositories so that you are working on the latest version of the main remote repository (upstream). First, make sure that you are on the master branch of your local repository. You do this by right-clicking on "master" in the branches dock and clicking on "Checkout", or by clicking on "Branch" in the menu and clicking on "Checkout...", then selecting the master branch. {{attachment:checkout1.png}} {{attachment:checkout2.png}} Now, you pull from upstream/master. You do this by clicking on "Actions" and clicking on "Pull...". Select upstream and master in the pop-up that appears. {{attachment:pull.png}} If you want, you can also add all the actions to the main window by clicking on "View" and selecting "Actions". This makes it a little more persistently obvious what actions are available to you. At this stage, the master branch of your local repository is identical to the master branch of the remote main repository. You can also update your remote repository by clicking on "Push". See picture. {{attachment:push.png}} This step is not absolutely necessary, but doesn't hurt. == Start on a new feature == Now that you have your master repository up-to-date, it is time to start working on something. Checkout to the master branch before beginning, then create a new branch for your feature. You do this by clicking on the "Branch" menu item and selecting "Create...". {{attachment:create.png}} You are now on your new branch. This is where you can leave Git alone, and just start working. When you are done, you return to Git and see a screen like this: {{attachment:status1.png}} This is where you can add files to the "staging area". This is basically a list of files that you would like to commit all at once. Everything ''outside'' of the staging area is not committed. To add files to the staging area, right-click on them and click "Stage Selected". When the staging area is properly populated, you can commit. By committing, you are basically declaring that you are confident in your changes, that they form a single cohesive whole, and that they are more-or-less complete. Let's do that now. Just type a title for the change, and optionally an additional description, and click "Commit". {{attachment:commit.png}} == Sharing your changes == If you did the above, you have now added a commit to a branch in your local repository. But you want to eventually get that commit into the master branch of the main remote repository. To do that, you have to follow a few steps. First, push your local commits to your remote repository. Click on "Actions", then "Push...", and configure three things: The remote you want to push to (origin), the local branch that you want to push (NAME-OF-FEATURE), and the remote branch that you want to push to (usually identically named, so NAME-OF-FEATURE). {{attachment:push2.png}} When you go to https://git.fsfe.org/YOURNAME/fsfe-website, your commit should now be visible in its own branch! This is good, because it means that your change is available online, and that others can view it. This also means that the maintainer of the main remote repository can view your changes. To ask the maintainer to pull your branch into the master branch of the main remote repository, you create a '''pull request'''. You do this by navigating to the main webpage the main remote repository and clicking on "Pull Requests". There, you can create a new pull request and specify that you would like the maintainer to update master (main) with NAME-OF-FEATURE (compare). Add a title and a description, and your work is done :-). The maintainer will review your changes and accept them when everything is okay. = Guide: Terminal workflow = == Setting up your local repository == Assuming you have set up your remote repository by clicking the "Fork" button on the main project page, you can now set up your local repository. {{{ |
{{{ |
| Line 120: | Line 108: |
| You have now cloned the '''master branch''' of fsfe-website. | Also, by cloning, you have implicitly configured a "remote" for your local repository. This remote is called '''origin''', and is equal to "git@git.fsfe.org:YOURNAME/fsfe-website.git". You might want to add an extra remote, however, pointing to the main remote repository. Let's do this now, and call it '''upstream'''. |
| Line 122: | Line 110: |
| Also, by typing that command, you have implicitly configured a "remote" for your local repository. This remote is called '''origin''', and is equal to "git@git.fsfe.org:YOURNAME/fsfe-website.git". You might want to add an extra remote, however, pointing to the main remote repository. Let's do this as follows, and call it '''upstream''': {{{ |
{{{ |
| Line 128: | Line 114: |
| Your local repository is now tracking two remote repositories, and you are ready to begin working. | |
| Line 130: | Line 115: |
| == Syncing all repositories == | |
| Line 132: | Line 116: |
| Before you start, you may want to synchronise all repositories so that you are working on the latest version of the main remote repository (upstream). This is fairly simple to do. | === Syncing all repositories === |
| Line 134: | Line 118: |
| {{{ | Before you start, you may want to synchronise all repositories so that you are working on the latest version of the main remote repository (upstream). {{{ |
| Line 145: | Line 131: |
| Line 147: | Line 134: |
| Let's begin changing something. Assuming that your local repository is up-to-date, you can create a new branch from master. We '''never make any changes directly to the master branch'''. | Let's begin changing something, e.g. adding a new translation. Assuming that [[#Syncing_all_repositories|your local repository is up-to-date]], you can create a new branch from master. We '''never make any changes directly to the master branch'''. |
| Line 149: | Line 136: |
| {{{ | {{{ |
| Line 155: | Line 142: |
| At this point, you can leave Git alone and begin working on the files. You only return to Git when you are done. After you are done, you can do something like this: | |
| Line 157: | Line 143: |
| {{{ | At this point, you leave Git alone and begin working on your changes. You only return to Git after you are done. When you are done, you add files to the '''staging area'''. This is basically a list of files that you would like to commit all at once. Everything ''outside'' of the staging area is not committed. When the staging area is properly populated, you can commit. By committing, you are basically declaring that you are confident in your changes, that they form a single cohesive whole, and that they are more-or-less complete. {{{ |
| Line 162: | Line 153: |
| # Let's add files to the "staging area". This is basically a list of files that # you would like to commit at once. |
# Let's add files to the staging area. |
| Line 169: | Line 159: |
| # When you are done setting up your "staging area", you can commit. By # committing, you are saying that you are confident in your changes and that # they are (more-or-less) complete. |
# When you are done setting up your staging area, you can commit. |
| Line 175: | Line 163: |
| == Sharing your changes == | === Sharing your changes === |
| Line 179: | Line 168: |
| First, you upload the branch with commits to your remote repository (origin): | First, you upload the branch with commits to your remote repository (origin). |
| Line 181: | Line 170: |
| {{{ | {{{ |
| Line 191: | Line 180: |
| = Miscellaneous tasks = | = Helpful commands = |
| Line 193: | Line 182: |
| Sections for misc. tasks go here, so they don't litter the main guide with superfluous information. | Below an uncomplete list of commands that prove to be useful. * `git status`: Always helpful to help you understand your latest edits. It also shows the branch you are currently working on * `git log`: Which changes took place in the past in this repository? Will show all commit messages, and with the unique identifiers of each commit you could explore more details. * `git diff`: Show a detailled difference log between the last ''official'' status and potential edits of yours which have not been committed yet. |
| Line 199: | Line 192: |
| There are also very many guides on how to use Git on the internet. [[https://www.atlassian.com/git|Atlassian]] and [[https://guides.github.com/|GitHub]] have some very detailed tutorials that may help you. | There are also very many guides on how to use Git on the internet. [[https://betterexplained.com/articles/a-visual-guide-to-version-control/|A visual guide to version control]] and its whole series explain it from a more non-technical side. [[https://www.atlassian.com/git|Atlassian]] and [[https://guides.github.com/|GitHub]] have some very detailed tutorials that may help you with more specific things. |
Common information
The workflow in Git is quite different from what you may be used to. This is because Git is decentralised. Every repository in Git is equal, but some repositories are more equal than others.
Before you start, make sure you have everything set up as described in TechDocs/Git/FirstSteps. Also make sure you understand basic Git commands as described in TechDocs/Git/FirstCommit.
This page explains two different scenarios.
A simple approach with direct edits to the Git repository. It's easier to understand but bears a few risks.
A more complex approach which involves forks and Pull Requests. This is safer and allows more checks. For example, we highly prefer this for changes on the fsfe.org website.
It will start with the simple approach which skips a lot of detailed information about the different aspects Git it built upon. If you don't understand something, please have a look into the complex approach, or skim external resources like the excellent Visual guide to version control and its following guides in the series.
Simple approach
This workflow reduces complexity by giving up the need of forks, extra branches and pull requests. While it's easier to learn, we require the complex approach for some repositories like the website because it's safer, more transparent and more reliable. Also, this method requires that you have at least write access to the repository.
In this example, it is assumed you would like to work on FSFE/share-buttons, an interesting but seldom used repository.
Basic knowledge
As with the complex workflow, you should rudimentally know about the scheme you are working with.
The Two Repositories
There are only two repositories you are working with:
The main remote repository or origin: https://git.fsfe.org/FSFE/share-buttons. This is the most important repository, because everyone has agreed that this is the "official" repository. You will directly be working on that.
Your local repository. This is the directory on your local computer. You also have complete control over this repository. Nothing you do in this repository affects any other repository until you push.
Branches
Unlike with the complex approach, branching will play no role in most repositories in which the simple workflow can be used. You will only work with the master branch which is the official "timeline" of the repository. Any change that you will make and upload to this branch will directly affect the local repositories of the others working on it as soon as they update to the latest status.
One-time preparations
In the following you'll find the steps which have to be execute only once per repository you want to work on. It is assumed that you successfully set up Git on your computer according to our recommendations.
Clone the repository to a place on your computer. Within a terminal, move to a location of your choice and execute git clone git@git.fsfe.org:FSFE/share-buttons.git. This will create a folder called share-buttons inside the directory your terminal has opened.
Workflow
After the one-time preparations, the following steps have to be execute in a terminal positioned in your local repository each time you would make an edit.
Before making any change, always do a git pull. This will update your local copy with the remote repository to get the latest changes.
- Now you can make any changes, e.g. create new files or edit existing ones. You can do that in your file browser.
Run git status to be presented with a list of edits you have done. This can be executed any time and will help you to understand the difference between the official status and your own edits.
In order to share your changes, you will have to add them. This has to be done for new, modified and deleted files, and will add them to the list of files you would like to share your modifications for: git add new_file1.txt modified_file2.jpg. Note that this can also be directories, and that you can add multiple files at once!
Now let's make it official! By committing your edits, you are required to describe them in order to allow others to understand them: git commit -m 'I did some modifications in order to solve this and that problem'. Please be informative and concise at the same time.
Your local copy has been changed, now push the changes online to all other people working on the repository: git push. That makes it official, and you can see it online.
Due to the disadvantages of this workflow, you shouldn't let pass too much time between the first and last step in order to avoid conflicts with potential edits of other people. Also, please make sure to double-check your edits since there is no check in between.
Complex approach
The complex workflow is recommended for intensively used repositories which are affected by many changes by multiple users. You will not work on the official repository directly but on your own copy ("fork") and ask a maintainer to include your changes to the official repositories in an extra step. Also, you can contribute to any public repository even if you don't have write access.
This guide is also written in a more verbose form than the simple approach. even if you feel confident that you are not required to know the advanced workflow, it probably will still help you to understand Git a bit better.
Basic knowledge
The three repositories
As a beginner, you only really need to know about three repositories that are relevant to you, and that you will interact with. For this guide, we will assume that we are working on fsfe-website. The three repositories are:
The main remote repository or upstream: https://git.fsfe.org/fsfe/fsfe-website. This is the most important repository, because everyone has agreed that this is the "official" repository.
Your remote repository or origin: https://git.fsfe.org/YOURNAME/fsfe-website. This repository is created when you click on the "Fork" button on the main repository's web page. At the time of pressing that button, it is basically identical to the main remote repository. But when changes are made to the main remote repository, those changes are not made to your remote repository, unless you manually push the same changes. This repository contains all the commits that you have made. You have complete control over this repository, and you can do with it as you like!
Your local repository. This is the directory on your local computer. You also have complete control over this repository. Nothing you do in this repository affects any other repository until you push.
These three terms will consistently be used in this guide. However, in the simple guide, the forked origin is not used as you are directly working on the main repository.
Branches
In Git, you will often be using branches. When you first visit a project's web page or first clone a project, you will see the master branch of that repository. This is the main branch in any repository.
Consider a branch like an independent alternate timeline of commits, where the master branch is the main timeline. So if you create a new branch from master, you are entering an alternate timeline that, from that point onward, is not affected by changes in master. You can merge that timeline back into master, though this is often done by the maintainer of the repository.
Similarly, when a new commit is added to the master branch of the main remote repository, that commit does not immediately appear on the master branch of your remote repository. You have to manually update this. This makes sense, because your repository is independently your own, and nobody else's.
You usually do not edit the master branch directly. Ideally, the master branch is identical between the main remote repository, your remote repository and your local repository, so that all repositories agree on the official series of commits. If you edit your own master branch, you are basically disagreeing with the main remote repository and creating your own "official" timeline. Which would be fine, if you were writing an alternate history novel, but you probably want to stick to the official master branch.
Workflow
This guide is way to create a new pull request, i.e. a proposal for an addition or change of yours to the upstream repository, mostly via the terminal. This solution is preferred over using graphical applications, because it is easier to ask someone to type a certain command, than it is to ask them to push some buttons.
Set up your repository
Please, keep in mind that for setting up git and cloning repository you will need from 2 to 3 hours of time! So it's better to do this when you come to the office in the morning.
Assuming you have set up your remote repository by clicking the "Fork" button on the main project page, you can now set up your local repository.
mkdir -p ~/FSFE # Create a directory to hold your local repositories cd ~/FSFE # Create your local repository by downloading your remote repository. git clone git@git.fsfe.org:YOURNAME/fsfe-website.git cd fsfe-website
Also, by cloning, you have implicitly configured a "remote" for your local repository. This remote is called origin, and is equal to "git@git.fsfe.org:YOURNAME/fsfe-website.git". You might want to add an extra remote, however, pointing to the main remote repository. Let's do this now, and call it upstream.
git remote add upstream git@git.fsfe.org:fsfe/fsfe-website.git
Syncing all repositories
Before you start, you may want to synchronise all repositories so that you are working on the latest version of the main remote repository (upstream).
git checkout master # Switch to the main branch. This is a branch in your # local repository. git pull upstream master # Pull the latest version of upstream into your local # branch. # Your local repository is now up-to-date! git push origin master # Let's also push the changes to your remote repository. # This is not strictly necessary.
Start on a new feature
Let's begin changing something, e.g. adding a new translation. Assuming that your local repository is up-to-date, you can create a new branch from master. We never make any changes directly to the master branch.
git checkout master # Make sure we are starting from master. git checkout -b NAME-OF-FEATURE # Create a new branch from master, and change # to it.
At this point, you leave Git alone and begin working on your changes. You only return to Git after you are done.
When you are done, you add files to the staging area. This is basically a list of files that you would like to commit all at once. Everything outside of the staging area is not committed. When the staging area is properly populated, you can commit. By committing, you are basically declaring that you are confident in your changes, that they form a single cohesive whole, and that they are more-or-less complete.
git status # Let's have a look at what branch we are on, and what files have # been changed. git diff # Let's see what exactly was changed. Press 'q' to exit. # Let's add files to the staging area. # # Use `git add FILE` to add to the staging area. # Use `git reset FILE` to remove from the staging area. git add path/to/file/that/changed # When you are done setting up your staging area, you can commit. git commit -m "MESSAGE DESCRIBING YOUR COMMITS"
Sharing your changes
If you did the above, you have now added a commit to a branch in your local repository. But you want to eventually get that commit into the master branch of the main remote repository. To do that, you have to follow a few steps.
First, you upload the branch with commits to your remote repository (origin).
git checkout NAME-OF-FEATURE # Make sure we're on the correct branch! git status # Double check whether everything is good. git push origin NAME-OF-FEATURE # Upload your branch
When you go to https://git.fsfe.org/YOURNAME/fsfe-website, your commit should now be visible in its own branch! This is good, because it means that your change is available online, and that others can view it. This also means that the maintainer of the main remote repository can view your changes.
To ask the maintainer to pull your branch into the master branch of the main remote repository, you create a pull request. You do this by navigating to the main webpage the main remote repository and clicking on "Pull Requests". There, you can create a new pull request and specify that you would like the maintainer to update master (main) with NAME-OF-FEATURE (compare). Add a title and a description, and your work is done :-). The maintainer will review your changes and accept them when everything is okay.
Helpful commands
Below an uncomplete list of commands that prove to be useful.
git status: Always helpful to help you understand your latest edits. It also shows the branch you are currently working on
git log: Which changes took place in the past in this repository? Will show all commit messages, and with the unique identifiers of each commit you could explore more details.
git diff: Show a detailled difference log between the last official status and potential edits of yours which have not been committed yet.
Questions
This guide is, and will probably always be, incomplete. Git is a very advanced piece of software. If you run into a problem that this guide does not explain, please ask a technically inclined person to add a section to the guide that sufficiently explains how to deal with that problem.
There are also very many guides on how to use Git on the internet. A visual guide to version control and its whole series explain it from a more non-technical side. Atlassian and GitHub have some very detailed tutorials that may help you with more specific things.
