Contribute using Git and GitHub
Initial setup and configuration #
GitHub Account #
Make an account on GitHub. A variety of plans are available, but a free account works just fine.
Set up Git #
Install Git following instructions from: Generating SSH Keys
Setup your personal info in local Git repo:
git config --global user.email "firstname.lastname@example.org"
git config --global user.name "Your Name"
Set SSH keys and add it to the GitHub account. For help, see GitHub's article https://help.github.com/articles/generating-ssh-keys
Retrieve Liferay source code #
Fork Liferay repositories #
Fork both the Liferay Portal and Liferay Plugins repositories to your GitHub account. Do this by visiting the repositories at the links below and then click the "Fork" button. You must be signed in to fork the repositories.
Clone forked repositories #
Clone your own forked GitHub repos. Go to a location on your computer that you wish to have a copy of the Liferay Portal and Liferay Plugins source stored. This could be a "Development" directory within your user's home directory, for example. Once in this location, issue the following git commands to clone your forked repositories to your computer:
git clone ssh://email@example.com/your-github-username/liferay-portal.git
git clone ssh://firstname.lastname@example.org/your-github-username/liferay-plugins.git
This may take a long time depending on your network connectivity -- grab a cup of coffee and wait it out.
Once it completes, you will see two new directories - liferay-portal and liferay-plugins. Inside each of these directories is the source code for each.
Configure remote upstream #
Set the remote upstream repository for both liferay-portal and liferay-plugins. Run the command below inside the liferay-portal directory. Then, change "liferay-portal.git" to "liferay-plugins.git" and run the command in the liferay-plugins directory, too.
git remote add upstream git://github.com/liferay/liferay-portal.git
Configure local master #
Create local master branch from the upstream. Run the command below inside the liferay-portal directory. Then, change to the liferay-plugins directory and run the same command.
git checkout -b master "upstream/master"
Now we have 3 repositories each for liferay-portal and liferay-plugins: local (on your computer), origin (your fork on GitHub) and the upstream (the main owned by Liferay on GitHub).
Sync changes from upstream #
If the main repository changes, you will need to sync changes from upstream. You can accomplish this with the following commands:
- Get all the updates from upstream
git fetch upstream
- Switch to the master branch
git checkout master
- Rebase the master branch. With rebase, all local commits are stashed and applied after the fetch
git pull --rebase upstream master
- Push the updates to origin
git push origin master
Now the local, origin, and upstream repositories are all current