YunoHost and all our apps are on the Git forge GitHub. Which means that if you want to work on an app, sooner or later you're going to have to deal with Git.
So let's see how to work with Git to be able to contribute in the context of YunoHost.
Branches are, as GitHub explains, "*a parallel version of a repository. It is contained within the repository, but does not affect the other branches. Allowing you to work freely without disrupting the "live" version.*"
The master branch is the branch that contains the version of the app users will actually install and use.
The usual thing to do is to work from the testing branch, and when everything is settled and tested, you can merge the testing branch in master, so users will enjoy the new release of your package.
If you don't have the permission to write on the repository, you will see (as on the picture) that you're going to create a fork (we'll see below what a fork is).
If you have the permission to write, you will just edit the file, without forking.
#### Commit your changes
When you're done with your modification on the file, you can commit your changes.
The first field is the name of your commit, a very short sentence to explain why you did this modification.
The second field is a large one for a more complete explanation, if you need it.
Finally, if you're editing a repository on which you have permission to write, you can either commit directly to the current branch or create a new branch.
It's usually better to create a new branch, that way you keep your modifications on a *parallel* version of the repository. Your modifications will be discussed in a pull request (explained below) then finally merged into the original branch.
But even if a fork is not the real repository, but just a copy, a fork is always linked to its parent. We'll see later that to create a fork is really useful when opening a pull request.
But, when you want to edit multiple files, the GitHub interface isn't really the best way. In such situation, you would rather clone the repository and work on a local repository.
You may still need to fork on your own account to be able to save your modifications if you don't have the permission on the distant repository.
#### Pull request
After you have committed your changes, whether on a branch or a fork, you want to propose your modifications to be integrated into the main repository, or the original branch.
To do so, you're going to *create a pull request*. GitHub usually ask you directly if you want to do so.
When creating a pull request from a fork, to ease the work of the reviewers, **do never** uncheck the checkbox *Allow edits from maintainers*. That option simply allow the maintainers of the original repository to edit directly your work.
Following the [YEP 1.7](https://github.com/YunoHost/doc/blob/master/packaging_apps_guidelines.md#yep-17), your app has to be into the YunoHost-Apps organization, but if you have never contributed to an app before or never had any app into this organization you may not have the permission.
You have shockingly discovered that the wonderful app you love to use everyday does not yet have its YunoHost package. And because you're nice, you decided to create yourself the package, so everyone will enjoy that app the way you do.
What a good idea !
The best is to start from the [example app](https://github.com/YunoHost/example_ynh). But as we have explained before, you don't want to fork, because if you do so, you're going to keep that link to the example app and it's really annoying.
So, you're going to do it differently. You're going to clone !
##### git clone
To clone, you're going to do:
```
git clone https://github.com/YunoHost/example_ynh
```
`git clone` will download a copy of the repository. You will have the complete repository, with its branches, commits, and everything (into that apparently little `.git` directory).
*A side note though, if you expect to send your modifications back to the distant repository on GitHub, be sure to have the permission to write on this repository. Otherwise, fork before and clone your fork, on which you do have the permission.*
##### My brand new package, continued
In the context of a new package, you will also need to create a repository on GitHub to nest your package.
Which is as simple as a big green *New* button.
Don't bother with README, .gitignore or license. Just create the repository itself.
You now have 2 repositories cloned on your computer.
Copy all the files from the example_ynh app, **except the .git directory** (You just want the files themselves) to your new package.
*If you want, you can remove the example_ynh app. We don't need it anymore.*
You're ready to work on your new package !
#### Second case: Working locally on a repository
You already have a repository, but what you want is just to work locally, so you can modify multiple files.
Simply clone the repository, the .git directory is the link to the distant repository. Nothing else to do than a `git clone`.
#### Branches
You do have your local copy of the repository, but because you have read carefully this documentation until then, you know that you should be sure to be on the testing branch before starting to work.
To see the branches, and to know on which you actually are, while into the directory of your repository, type `git branch`.
The current branch is highlighted and preceded by a `*`.
#### git checkout
If it appears that you're not on the branch you wanted to be, or you're actually on master (which is bad !), you can move to another branch with `git checkout`
*Sometimes, you will encounter an impossible situation where Git is saying that you can't pull because you have local changes. But you don't care of those local modifications, you just want to get the last version of the distant branch. But Git don't care about what YOU want...*
If you want to validate all your work, you can also simply do
```
git add --all
```
To check the current status of your validation, you can use `git status`. It will show you which files will be included into your commit, and which files are modified, but not yet included.
`git status -v` will show also which part of the files are modified. A good way to be sure that you didn't make a mistake before committing.
#### git checkout -b
Before committing, or after, or before starting to work. Whenever you feel like it !
You should consider adding your work to a separate branch, that way, it will be easy to create a pull request to merge into the testing branch and discuss with the other packagers what you suggest to change.
To create a new branch and move to this branch, you can use `git checkout -b my_new_branch`.
To have the same fields that you had on GitHub, with the name of the commit, and a longer explanation. You can simply use `git commit`.
The first line, before the comments, is for the name of the commit.
After all the comments, you can add an explanation if you want to.
If you want to commit with only a name for your commit, you can use a simple command:
```
git commit -m "My commit name"
```
#### Push to the distant repository
Your changes are validated, but only on your local clone of the repository. Now, you have to send those modifications back to the distant repository on GitHub.
In order to do that, you need to know what is your current branch. (If you don't know, `git branch` will give you that info).