Last updated 3 February 2018.

To work with Drupal you have to clone the Drupal project:

git clone

But to work only with the latest version of Drupal 7 clone the central Git repository:

git clone --branch 7.x 
cd drupal

The command above creates a tracking branch and checks out the branch (in addition to cloning the repository).

If the clone command doesn't work for you because you have an older version of Git, see Troubleshooting 'git clone'. (You'll have to adopt the initial checkout command for the 8.x branch below too.)

When cloning, a new Git repository is created in the (sub) directory drupal. All further work and git commands should be done from inside that directory.

Next, we will setup the repository to pull the Drupal 8 code as well. Switch to the Drupal 8 branch with:

git checkout 8.0.x

(Do not use git checkout -b 8.x since that creates a non-tracking branch.)
Use same way as Drupal 7:

git clone --branch 8.4.x
cd drupal

Now that you are on the Drupal 8 branch you can download the latest code with git pull.

Use git pull regularly to update your local copy of the code. Use git diff to roll your patches.

You can easily switch back to Drupal 7 with

git checkout 7.x