Diff for "TechDocs/Git/Workflow"

Differences between revisions 10 and 34 (spanning 24 versions)
Revision 10 as of 2017-09-11 09:01:36
Size: 9101
Editor: carmenbianca
Comment:
Revision 34 as of 2018-10-23 13:22:57
Size: 8848
Editor: max.mehl
Comment: remove graphical guide as we cannot support it
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
<<TableOfContents()>> ## page was renamed from TechDocs/Git/Guide:Workflow
<<TableOfContents(2)>>
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 13: Line 14:
 * 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 21: Line 22:
= Guide: Graphical workflow = == A note on branches ==
Line 23: Line 24:
This guide is for those who want to use Git with a graphical user interface (the Gitea web interface). The instructions here should translate loosely between different interfaces. 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.
Line 25: Line 26:
Note also that, because we are using the web interface, we do not have a local repository. Thus you only need to keep track of two repositories: The main remote repository and your remote 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.

= Guide =

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 29: Line 38:
To fork the main remote repository and set up your own, click the fork button in the top right of the main remote repository's main page and proceed.

{{attachment:fork.png}}

{{attachment:fork2.png}}

== A note on branches ==

After you have forked the repository, you should land on the page of your own remote repository. It is important to note now that you are viewing the '''master branch''' of your remote repository. This is the main branch in ''any'' repository. However, this is not usually the branch you want to work on. Consider a branch like an '''alternate timeline of commits''', where the master branch is the main timeline.

You want to keep the master branch of your remote repository identical to the master branch of the main remote repository. That way, you both agree on what the proper timeline of commits is.

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.

To sync your remote repository with the main remote repository, you have to follow a few steps.

= Guide: Terminal workflow =

== Setting up your local 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 51: Line 42:
{{{  {{{
Line 60: Line 51:
There are a few things you need to know at this point. By default, your local repository is set to work on the '''master branch'''. This is the main branch in ''any'' repository. However, this is not usually the branch you want to work on. Consider a branch like an '''alternate timeline of commits''', where the master branch is the main timeline. 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 62: Line 53:
Also, your local repository has a "remote" configured. 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 68: Line 57:
Your local repository is now tracking two remote repositories, and you are ready to begin working.
Line 72: Line 61:
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. 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 74: Line 63:
{{{  {{{
Line 85: Line 74:
Line 87: Line 77:
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'''.  You could, but it is highly advised against. If you did commit directly to the master branch, your master branch would be out-of-sync with the master branch of upstream, which we do not want! We want our master branches to be the same. 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 89: Line 79:
{{{  {{{
Line 95: Line 85:
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 97: Line 86:
{{{ 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 102: Line 96:
# 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 109: Line 102:
# 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 114: Line 105:
Line 119: Line 111:
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 121: Line 113:
{{{  {{{
Line 131: Line 123:
= Miscellaneous tasks =

Sections for misc. tasks go here, so they don't litter the main guide with superfluous information.

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

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.

A note on 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.

Guide

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.

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. Atlassian and GitHub have some very detailed tutorials that may help you.

TechDocs/Git/Workflow (last edited 2023-09-14 13:35:25 by irakli)