Working with git and github: Difference between revisions

From Joomla! Documentation

MATsxm (talk | contribs)
Marked for translation
MATsxm (talk | contribs)
Marked this version for translation
Line 2: Line 2:
{{underconstruction}}
{{underconstruction}}
<translate>
<translate>
= Intro =
= Intro = <!--T:1-->
</translate>
</translate>
<translate>This document will provide information about contributing to the Joomla! CMS with help of Git and GitHub. If you like to made a simple change (one file only), it is easier to use this documentation: [[S:MyLanguage/Using the Github UI to Make Pull Requests|Using the Github UI to Make Pull Requests]]
<translate><!--T:2-->
This document will provide information about contributing to the Joomla! CMS with help of Git and GitHub. If you like to made a simple change (one file only), it is easier to use this documentation: [[S:MyLanguage/Using the Github UI to Make Pull Requests|Using the Github UI to Make Pull Requests]]
If you like to add more complex changes or you're just interested in this, keep reading!</translate>
If you like to add more complex changes or you're just interested in this, keep reading!</translate>


<translate>
<translate>
== What are Git and GitHub? ==
== What are Git and GitHub? == <!--T:3-->
</translate>
</translate>


<translate>Git is a distributed version control system. It is a system that records changes in files, and keep this changes in history. So you can always look back to an earlier version of you're code and restore changes if you like. Because of the history, Git is very useful when you work with many people together on the same project.</translate>
<translate><!--T:4-->
Git is a distributed version control system. It is a system that records changes in files, and keep this changes in history. So you can always look back to an earlier version of you're code and restore changes if you like. Because of the history, Git is very useful when you work with many people together on the same project.</translate>


<translate>On this moment GitHub can be used. [https://www.github.com GitHub] is an website, what helps manage Git Projects in a visual way. As owner of a project you can change the code, and compare different versions. As user of the project you can contribute by making an Pull Request. A Pull request is a request to pull some code in that project. You're offering a piece of code, what can be a solution for a bug for example, and asking if the Project owner(s) like to use it. If the owner likes it, he can merge (add) it to his project.</translate>
<translate><!--T:5-->
On this moment GitHub can be used. [https://www.github.com GitHub] is an website, what helps manage Git Projects in a visual way. As owner of a project you can change the code, and compare different versions. As user of the project you can contribute by making an Pull Request. A Pull request is a request to pull some code in that project. You're offering a piece of code, what can be a solution for a bug for example, and asking if the Project owner(s) like to use it. If the owner likes it, he can merge (add) it to his project.</translate>


<translate>Joomla! uses GitHub and Git to maintain it's code. So everyone can contribute to Joomla! if they like to. The URL to the Joomla! CMS Project on GitHub is: https://github.com/joomla/joomla-cms</translate>
<translate><!--T:6-->
Joomla! uses GitHub and Git to maintain it's code. So everyone can contribute to Joomla! if they like to. The URL to the Joomla! CMS Project on GitHub is: https://github.com/joomla/joomla-cms</translate>


<translate>
<translate>
= Getting Started =
= Getting Started = <!--T:7-->
</translate>
</translate>
<translate>
<translate>
== Sign up on GitHub and install Git ==
== Sign up on GitHub and install Git == <!--T:8-->
</translate>
</translate>
<translate>First, you will need to register at [http://www.github.com GitHub]. It's free and very easy to do, just follow the provided steps.</translate>
<translate><!--T:9-->
First, you will need to register at [http://www.github.com GitHub]. It's free and very easy to do, just follow the provided steps.</translate>


<translate>One we are signed up, we need to install Git. The latest version of Git can be found on http://git-scm.com. Download and open the installer. Git is an CLI program, CLI mean Command Line Interface. At the begin this can be confusing and a little bit scared. There is no need for that, this document will lead you to the whole process.</translate>
<translate><!--T:10-->
One we are signed up, we need to install Git. The latest version of Git can be found on http://git-scm.com. Download and open the installer. Git is an CLI program, CLI mean Command Line Interface. At the begin this can be confusing and a little bit scared. There is no need for that, this document will lead you to the whole process.</translate>


<translate>If you're not an advanced user you can just run the installer and press the "next" button until the program will install. Git won't damage you're system, and later you can remove it just like other programs if you like too.</translate>
<translate><!--T:11-->
If you're not an advanced user you can just run the installer and press the "next" button until the program will install. Git won't damage you're system, and later you can remove it just like other programs if you like too.</translate>


<translate>Once we installed Git, we open the program called "Git Bash", and a command line will be opened. We going to tell Git our name and email adres. Git will use this information when we contribute to a project.</translate>
<translate><!--T:12-->
<translate>With the following commands we give Git that information:</translate>
Once we installed Git, we open the program called "Git Bash", and a command line will be opened. We going to tell Git our name and email adres. Git will use this information when we contribute to a project.</translate>
<translate><!--T:13-->
With the following commands we give Git that information:</translate>


<source>
<source>
Line 37: Line 46:
</source>
</source>


<translate>In the above commands, and all other commands given in this documentation, each line is a new command. So you type the fist line, presses enter and then type the second line and press enter.</translate>
<translate><!--T:14-->
In the above commands, and all other commands given in this documentation, each line is a new command. So you type the fist line, presses enter and then type the second line and press enter.</translate>


<translate>We are now ready to use Git, and go farther with setting up our test installation.</translate>
<translate><!--T:15-->
We are now ready to use Git, and go farther with setting up our test installation.</translate>


<translate>
<translate>
=Setting up a test installation=
=Setting up a test installation= <!--T:16-->
</translate>
</translate>
<translate>For our test installation we need a program that can simulate a webserver. So we can install and run Joomla! on our computer. There are a lot of program witch can do that. For example [https://www.mamp.info/ MAMP] or [https://www.apachefriends.org/ XAMPP]. Download an install one of them.</translate>
<translate><!--T:17-->
For our test installation we need a program that can simulate a webserver. So we can install and run Joomla! on our computer. There are a lot of program witch can do that. For example [https://www.mamp.info/ MAMP] or [https://www.apachefriends.org/ XAMPP]. Download an install one of them.</translate>


<translate>After the installation of such a program (I use MAMP in this documentation), we going to install the latest version of Joomla!. In our case, the latest version of Joomla! is not the last stable release. The last version of Joomla! is the staging branch on GitHub.
<translate><!--T:18-->
After the installation of such a program (I use MAMP in this documentation), we going to install the latest version of Joomla!. In our case, the latest version of Joomla! is not the last stable release. The last version of Joomla! is the staging branch on GitHub.
First, let me explain a little bit more about GitHub.</translate>
First, let me explain a little bit more about GitHub.</translate>


<translate>
<translate>
== Fork and clone Joomla! ==
== Fork and clone Joomla! == <!--T:19-->
</translate>
</translate>
<translate>On GitHub you can find projects, so called Repositories. Inside a project you can made several version, such a version is called a Branch. Joomla! has the following branches:</translate>
<translate><!--T:20-->
<translate>* '''Staging:''' This branch contains the latest bug fixes and new features of Joomla!</translate>
On GitHub you can find projects, so called Repositories. Inside a project you can made several version, such a version is called a Branch. Joomla! has the following branches:</translate>
<translate>* '''Master:''' This branch is the current stable version of Joomla!</translate>
<translate><!--T:21-->
<translate>* '''3.5-dev''' This branch contains the files for Joomla! 3.5, witch is not stable at the moment of writing.</translate>
* '''Staging:''' This branch contains the latest bug fixes and new features of Joomla!</translate>
<translate><!--T:22-->
* '''Master:''' This branch is the current stable version of Joomla!</translate>
<translate><!--T:23-->
* '''3.5-dev''' This branch contains the files for Joomla! 3.5, witch is not stable at the moment of writing.</translate>


<translate>On our test location we going to use the '''Staging''' branch. But if we should use this branch directly we have problem. We can not modify this branch because we are not the owner of it.</translate>
<translate><!--T:24-->
<translate>What we going to do, is making a copy of it, on GitHub this is called a Fork. We are the owner of that copy so we can modify it, and after modifying we compare our fork with the original project. At that moment we can make a Pull Request for the changes we made. More about that later in this documentation.</translate>
On our test location we going to use the '''Staging''' branch. But if we should use this branch directly we have problem. We can not modify this branch because we are not the owner of it.</translate>
<translate>You can Fork a branch by press the Fork button on the [https://github.com/joomla/joomla-cms Joomla! CMS Github Repository]. This button is located at the right top of the page.</translate>
<translate><!--T:25-->
What we going to do, is making a copy of it, on GitHub this is called a Fork. We are the owner of that copy so we can modify it, and after modifying we compare our fork with the original project. At that moment we can make a Pull Request for the changes we made. More about that later in this documentation.</translate>
<translate><!--T:26-->
You can Fork a branch by press the Fork button on the [https://github.com/joomla/joomla-cms Joomla! CMS Github Repository]. This button is located at the right top of the page.</translate>
[[File:Github-fork-button.png|none]]
[[File:Github-fork-button.png|none]]


<translate>After forking, we are going to install Joomla! on our local Web Server. Go to the folder were you can run files on you web server. Most of the program use a folder called <tt>htdocs</tt>. Once we are inside that folder, press the right mouse button an click on: "Git Bash Here". The command line will open for this location.</translate>
<translate><!--T:27-->
After forking, we are going to install Joomla! on our local Web Server. Go to the folder were you can run files on you web server. Most of the program use a folder called <tt>htdocs</tt>. Once we are inside that folder, press the right mouse button an click on: "Git Bash Here". The command line will open for this location.</translate>


<translate>Type the following command to download the files form your Fork of the Joomla! CMS your computer. Please replace <i>username</i> with the username you are using on GitHub.</translate>
<translate><!--T:28-->
Type the following command to download the files form your Fork of the Joomla! CMS your computer. Please replace <i>username</i> with the username you are using on GitHub.</translate>


<source>
<source>
Line 70: Line 92:
</source>
</source>


<translate>For all commands given in this documentation, you have to open Git via the above described steps. Please remember that for other commands in this documentation.</translate>  
<translate><!--T:29-->
For all commands given in this documentation, you have to open Git via the above described steps. Please remember that for other commands in this documentation.</translate>  


<translate>Once Git is ready, open your browsers and go to the installation on you localhost. Mostly the URL is something like: <tt>http://localhost/joomla-cms</tt>. You will now see the default Joomla! installation process.</translate>  
<translate><!--T:30-->
Once Git is ready, open your browsers and go to the installation on you localhost. Mostly the URL is something like: <tt>http://localhost/joomla-cms</tt>. You will now see the default Joomla! installation process.</translate>  


<translate>
<translate>
== Install Joomla! ==
== Install Joomla! == <!--T:31-->
</translate>
</translate>
<translate>The installation of Joomla! for our local test installation is almost the same as and regular installation. There are a two little difference.</translate>
<translate><!--T:32-->
The installation of Joomla! for our local test installation is almost the same as and regular installation. There are a two little difference.</translate>


<translate>For the database settings, the password and username are default. So mostly the username is <tt>root</tt> and the password is also <tt>root</tt> or there is no password. If your still can't connect to the database, look in the manual for you local webserver for the username and password.</translate>
<translate><!--T:33-->
For the database settings, the password and username are default. So mostly the username is <tt>root</tt> and the password is also <tt>root</tt> or there is no password. If your still can't connect to the database, look in the manual for you local webserver for the username and password.</translate>


<translate>The last difference is the last step of the installation. Normally we must delete the installation folder to go further to the back-end or front-end of Joomla!. For a test installation we can skip this part, and we can directly go the back-end or front-end. Don't removing the instillation folder can be very useful when we have to install Joomla again.</translate>
<translate><!--T:34-->
The last difference is the last step of the installation. Normally we must delete the installation folder to go further to the back-end or front-end of Joomla!. For a test installation we can skip this part, and we can directly go the back-end or front-end. Don't removing the instillation folder can be very useful when we have to install Joomla again.</translate>


<translate>
<translate>
=Make your changes=
=Make your changes= <!--T:35-->
</translate>
</translate>
<translate>Now it is time to made our file change to Joomla!. All changes we make, will be registered and monitored by Git. At any moment you can type the command <tt>git status</tt> to see witch files are modified or untracked. Untracked means that the file on that location is new for Git.</translate>
<translate><!--T:36-->
Now it is time to made our file change to Joomla!. All changes we make, will be registered and monitored by Git. At any moment you can type the command <tt>git status</tt> to see witch files are modified or untracked. Untracked means that the file on that location is new for Git.</translate>


<translate>If you made a mistake or like to restore a file you can use this command:</translate>
<translate><!--T:37-->
If you made a mistake or like to restore a file you can use this command:</translate>


<source>
<source>
Line 94: Line 123:
</source>
</source>


<translate>If you like to remove all changes you made you can use the following commands:</translate>
<translate><!--T:38-->
If you like to remove all changes you made you can use the following commands:</translate>


<source>
<source>
Line 101: Line 131:
</source>
</source>


<translate>The first command reset all file, and the second command removes untracked files and folders.</translate>
<translate><!--T:39-->
The first command reset all file, and the second command removes untracked files and folders.</translate>


<translate>
<translate>
==Public our changes on GitHub==
==Public our changes on GitHub== <!--T:40-->
</translate>
</translate>
<translate>
<translate>
=Push the change to our fork=
=Push the change to our fork= <!--T:41-->
</translate>
</translate>
<translate>After making our changes, we have upload our changes to our repository on GitHub. After that, we can make a pull request with our changes.</translate>
<translate><!--T:42-->
After making our changes, we have upload our changes to our repository on GitHub. After that, we can make a pull request with our changes.</translate>


<translate>Upload our changes is called <tt>push</tt> in Git terms. But before we can do that, we have to do something very important. We must create a new branch for our changes (A branch is a version of our project, remember?). If we don't do that and made our change directly to the staging branch, the first time there won't be a problem. But if we made changes for the second time, and the change we made the first time are not merged yet, all that changes will registered too as new changes.</translate>
<translate><!--T:43-->
Upload our changes is called <tt>push</tt> in Git terms. But before we can do that, we have to do something very important. We must create a new branch for our changes (A branch is a version of our project, remember?). If we don't do that and made our change directly to the staging branch, the first time there won't be a problem. But if we made changes for the second time, and the change we made the first time are not merged yet, all that changes will registered too as new changes.</translate>


<translate>So the first command we are going to run will create a new branch, to prevent the above described problem.
<translate><!--T:44-->
So the first command we are going to run will create a new branch, to prevent the above described problem.
Replace name-new-branch with the name of the new branch. This name must be short, and can only contain lower case letters, number and do '''NOT''' have space. Instead of spaces use - (minus)</translate>
Replace name-new-branch with the name of the new branch. This name must be short, and can only contain lower case letters, number and do '''NOT''' have space. Instead of spaces use - (minus)</translate>


Line 120: Line 154:
</source>
</source>


<translate>The next command tells git that all made changes are good, and are ready to commit.</translate>
<translate><!--T:45-->
The next command tells git that all made changes are good, and are ready to commit.</translate>


<source>
<source>
Line 126: Line 161:
</source>
</source>


<translate>The following command add our change to the branch. Please replace message with a short description of your changes. This description will be the title of the pull request we are going to make.</translate>
<translate><!--T:46-->
The following command add our change to the branch. Please replace message with a short description of your changes. This description will be the title of the pull request we are going to make.</translate>


<source>
<source>
Line 132: Line 168:
</source>
</source>


<translate>The final command will push (upload) the changes to our fork. Pleas replace name-new-branch with the name of the branch you made a few steps above.</translate>
<translate><!--T:47-->
The final command will push (upload) the changes to our fork. Pleas replace name-new-branch with the name of the branch you made a few steps above.</translate>


<source>
<source>
Line 139: Line 176:


<translate>
<translate>
==Compare forks and make a pull request==
==Compare forks and make a pull request== <!--T:48-->
</translate>
</translate>
<translate>After pushing our change to GitHub, go to your fork of the Joomla! CMS.</translate>
<translate><!--T:49-->
After pushing our change to GitHub, go to your fork of the Joomla! CMS.</translate>


<translate>
<translate>
=Extra information=
=Extra information= <!--T:50-->
</translate>
</translate>
<translate>Because the staging version of Joomla! can change any moment, it is very useful to have the possibility for keeping our fork up-to-date. We can do that by adding a remote to our forked project:</translate>
<translate><!--T:51-->
Because the staging version of Joomla! can change any moment, it is very useful to have the possibility for keeping our fork up-to-date. We can do that by adding a remote to our forked project:</translate>


<source>
<source>
Line 152: Line 191:
</source>
</source>


<translate>We now added a remote called "upstream". With the following command, Git will search for new contribution (commits) in the staging branch we don't have in our fork. If it found some, it will add them to our fork:</translate>
<translate><!--T:52-->
We now added a remote called "upstream". With the following command, Git will search for new contribution (commits) in the staging branch we don't have in our fork. If it found some, it will add them to our fork:</translate>


<source>
<source>
Line 158: Line 198:
</source>
</source>


<translate>The changes are now only made on our local fork. To upload them to GitHub use the following command:</translate>
<translate><!--T:53-->
The changes are now only made on our local fork. To upload them to GitHub use the following command:</translate>


<source>
<source>
Line 166: Line 207:
<noinclude>
<noinclude>
<translate>
<translate>
<!--T:54-->
[[Category: Bug Squad]]
[[Category: Bug Squad]]
[[Category: Development]]
[[Category: Development]]

Revision as of 16:14, 25 October 2015

Under Construction

This article or section is in the process of an expansion or major restructuring. You are welcome to assist in its construction by editing it as well. If this article or section has not been edited in several days, please remove this template.
This article was last edited by MATsxm (talk| contribs) 10 years ago. (Purge)

Intro

This document will provide information about contributing to the Joomla! CMS with help of Git and GitHub. If you like to made a simple change (one file only), it is easier to use this documentation: Using the Github UI to Make Pull Requests If you like to add more complex changes or you're just interested in this, keep reading!

What are Git and GitHub?

Git is a distributed version control system. It is a system that records changes in files, and keep this changes in history. So you can always look back to an earlier version of you're code and restore changes if you like. Because of the history, Git is very useful when you work with many people together on the same project.

On this moment GitHub can be used. GitHub is an website, what helps manage Git Projects in a visual way. As owner of a project you can change the code, and compare different versions. As user of the project you can contribute by making an Pull Request. A Pull request is a request to pull some code in that project. You're offering a piece of code, what can be a solution for a bug for example, and asking if the Project owner(s) like to use it. If the owner likes it, he can merge (add) it to his project.

Joomla! uses GitHub and Git to maintain it's code. So everyone can contribute to Joomla! if they like to. The URL to the Joomla! CMS Project on GitHub is: https://github.com/joomla/joomla-cms

Getting Started

Sign up on GitHub and install Git

First, you will need to register at GitHub. It's free and very easy to do, just follow the provided steps.

One we are signed up, we need to install Git. The latest version of Git can be found on http://git-scm.com. Download and open the installer. Git is an CLI program, CLI mean Command Line Interface. At the begin this can be confusing and a little bit scared. There is no need for that, this document will lead you to the whole process.

If you're not an advanced user you can just run the installer and press the "next" button until the program will install. Git won't damage you're system, and later you can remove it just like other programs if you like too.

Once we installed Git, we open the program called "Git Bash", and a command line will be opened. We going to tell Git our name and email adres. Git will use this information when we contribute to a project. With the following commands we give Git that information:

git config --global user.name "Your name"
git config --global user.email youremail@mail.com

In the above commands, and all other commands given in this documentation, each line is a new command. So you type the fist line, presses enter and then type the second line and press enter.

We are now ready to use Git, and go farther with setting up our test installation.

Setting up a test installation

For our test installation we need a program that can simulate a webserver. So we can install and run Joomla! on our computer. There are a lot of program witch can do that. For example MAMP or XAMPP. Download an install one of them.

After the installation of such a program (I use MAMP in this documentation), we going to install the latest version of Joomla!. In our case, the latest version of Joomla! is not the last stable release. The last version of Joomla! is the staging branch on GitHub. First, let me explain a little bit more about GitHub.

Fork and clone Joomla!

On GitHub you can find projects, so called Repositories. Inside a project you can made several version, such a version is called a Branch. Joomla! has the following branches:

  • Staging: This branch contains the latest bug fixes and new features of Joomla!
  • Master: This branch is the current stable version of Joomla!
  • 3.5-dev This branch contains the files for Joomla! 3.5, witch is not stable at the moment of writing.

On our test location we going to use the Staging branch. But if we should use this branch directly we have problem. We can not modify this branch because we are not the owner of it. What we going to do, is making a copy of it, on GitHub this is called a Fork. We are the owner of that copy so we can modify it, and after modifying we compare our fork with the original project. At that moment we can make a Pull Request for the changes we made. More about that later in this documentation. You can Fork a branch by press the Fork button on the Joomla! CMS Github Repository. This button is located at the right top of the page.

After forking, we are going to install Joomla! on our local Web Server. Go to the folder were you can run files on you web server. Most of the program use a folder called htdocs. Once we are inside that folder, press the right mouse button an click on: "Git Bash Here". The command line will open for this location.

Type the following command to download the files form your Fork of the Joomla! CMS your computer. Please replace username with the username you are using on GitHub.

git clone https://github.com/username/joomla-cms.git

For all commands given in this documentation, you have to open Git via the above described steps. Please remember that for other commands in this documentation.

Once Git is ready, open your browsers and go to the installation on you localhost. Mostly the URL is something like: http://localhost/joomla-cms. You will now see the default Joomla! installation process.

Install Joomla!

The installation of Joomla! for our local test installation is almost the same as and regular installation. There are a two little difference.

For the database settings, the password and username are default. So mostly the username is root and the password is also root or there is no password. If your still can't connect to the database, look in the manual for you local webserver for the username and password.

The last difference is the last step of the installation. Normally we must delete the installation folder to go further to the back-end or front-end of Joomla!. For a test installation we can skip this part, and we can directly go the back-end or front-end. Don't removing the instillation folder can be very useful when we have to install Joomla again.

Make your changes

Now it is time to made our file change to Joomla!. All changes we make, will be registered and monitored by Git. At any moment you can type the command git status to see witch files are modified or untracked. Untracked means that the file on that location is new for Git.

If you made a mistake or like to restore a file you can use this command:

git checkout path/to/file

If you like to remove all changes you made you can use the following commands:

git checkout .
git clean -f -d

The first command reset all file, and the second command removes untracked files and folders.

Public our changes on GitHub

Push the change to our fork

After making our changes, we have upload our changes to our repository on GitHub. After that, we can make a pull request with our changes.

Upload our changes is called push in Git terms. But before we can do that, we have to do something very important. We must create a new branch for our changes (A branch is a version of our project, remember?). If we don't do that and made our change directly to the staging branch, the first time there won't be a problem. But if we made changes for the second time, and the change we made the first time are not merged yet, all that changes will registered too as new changes.

So the first command we are going to run will create a new branch, to prevent the above described problem. Replace name-new-branch with the name of the new branch. This name must be short, and can only contain lower case letters, number and do NOT have space. Instead of spaces use - (minus)

git checkout -b name-new-branch

The next command tells git that all made changes are good, and are ready to commit.

git add --all

The following command add our change to the branch. Please replace message with a short description of your changes. This description will be the title of the pull request we are going to make.

git commit -m "description"

The final command will push (upload) the changes to our fork. Pleas replace name-new-branch with the name of the branch you made a few steps above.

git push origin name-new-branch

Compare forks and make a pull request

After pushing our change to GitHub, go to your fork of the Joomla! CMS.

Extra information

Because the staging version of Joomla! can change any moment, it is very useful to have the possibility for keeping our fork up-to-date. We can do that by adding a remote to our forked project:

git remote add upstream https://github.com/joomla/joomla-cms.git

We now added a remote called "upstream". With the following command, Git will search for new contribution (commits) in the staging branch we don't have in our fork. If it found some, it will add them to our fork:

git pull upstream staging

The changes are now only made on our local fork. To upload them to GitHub use the following command:

git push