Skip to content

Enough git to be dangerous

MathieuB8 edited this page Dec 2, 2017 · 6 revisions

To contribute to this project with basic PRs, here is all you need to know.

This is not a replacement for learning git, which you will have to do eventually if you want to understand what you're doing.

Install git

On Linux, use your package manager to install git, on Windows, install Git for Windows.

Fork and clone

Fork this repo to your personal Github account using the "Fork" button on the main github page. On your new repo page, use the "Clone or download" button to get a clone url (if you set up SSH Keys, you can use the SSH link, if you use the HTTPS link, you will need to use your Github username and password for pushing.)

Set up the upstream repo as a remote:

git remote add upstream https://github.com/FAForever/client.git

Create a feature branch

git checkout can be used to switch to a branch (It can also do other things, but that's not important for us right now). E.g. git checkout develop will switch to the develop branch. git checkout -b will create a new branch:

git checkout -b fix/1111-some-bug

This branch will be branching off of the branch you were on when you issued the command. You generally want to branch from develop.

Make sure your develop branch is up to date before creating a feature branch:

git checkout develop
git pull upstream develop
git checkout -b fix/1111-some-bug

Make changes

Now you can edit files and commit them using git commit -a. Don't forget to use git add for new files!

Push your changes

You will push your feature branch to your personal fork:

git push -u origin fix/1111-some-bug

Running this initially with -u sets your feature branch to track this remote branch, and after you've done that once, you can just use

git push

to do the same without typing out the remote branch again.

After pushing your branch, you will be able to open a PR with it on Github.

Rebase

If the upstream repository gets new commits while you were working on your changes, that means the git history of the upstream and your feature branch are diverging.

To fix that, you have to rebase. The easiest way to do that is to do a pull with rebase:

git pull --rebase upstream develop

This pulls from the upstream(!) repo and rebases all your changes onto it. The rebase means all your commits will change, so you will then have to do a force push:

git push -f

Only make a force push after rebasing - it's easy to accidentally force-push over something you didn't intend to!

If you are working on a feature branch for some time, it is good practive to do a rebase every time before you start work. This minimizes the amount of potential conflicts you will have to resolve.

How to fork a fork project whereas you already forked the main project (you can't fork a fork) :

-Clone your repository 'randomdude' on your computer :

git clone https://github.com/randomdude

-Add the repository you want to fork from (f1 will be the name of the remote):

git remote add f1 https://github.com/duk3luk3/client

You can verify it by doing it :

git remote -v
f1      https://github.com/duk3luk3/client (fetch)
f1      https://github.com/duk3luk3/client (push)
origin  https://github.com/randomdude/client (fetch)
origin  https://github.com/randomdude/client (push)

-Get the branch called 'add-faf-api-support' from the remote f1 :

git fetch f1 add-faf-api-support

-Make a branch 'viewaliases-api' which is tracking the branch 'add-faf-api-support' of remote 'f1' :

git checkout -b 'viewaliases-api' f1/add-faf-api-support

-Add your changes to the files then :

git add .
git commit -m "whatever commit message you want"
git push origin