Git Cheat Sheet

This is a short list of commands. If you are not familiar with the workflow yet, make sure you follow the link at the beginning of each section and read the detailed description.

The following commands assume you are in the working directory of the TYPO3 core repository.

git clone

Clone TYPO3 CMS Git repository into current directory:

shell command
git clone git@github.com:typo3/typo3 .
Copied!

Setup

For detailed setup instructions, please see: Git Setup

Migrations

Migrate master => main

If you are using an older installation with the master branch you can switch like this from master to main:

shell command
# Make sure that git pull loads from the "main" branch
git branch --set-upstream-to origin/main

# Rename your current "master" branch locally to "main" to match TYPO3's naming scheme
git branch -m master main
Copied!

Please also adapt your commit message template (if configured) to use "main" instead of "master".

Migrate to GitHub

If you are working with an older t3coredev installation and are not using the GitHub URL yet, you can switch like this:

shell command
# set remote url for "origin"
git remote set-url origin https://github.com/typo3/typo3.git
# set push URL to gerrit (this has not changed)
git config remote.origin.pushurl "ssh://<your-username>@review.typo3.org:29418/Packages/TYPO3.CMS.git"
Copied!

Workflow - common commands

For details see Create a Patch

Reset repo to last remote commit in (remote) main branch:

shell command
git reset --hard origin/main && git pull origin main
Copied!

Stage and commit all changes:

shell command
git commit -a
Copied!

Is the same as:

shell command
git add .
git commit
Copied!

Stage and commit all changes to already existing commit:

shell command
git commit -a --amend
Copied!

Push changes to remote main branch on gerrit (default method):

shell command
git push
Copied!

This assumes, you have correctly configured your remote as described in Setting up Your Remote. If not, you must explicitly push using the refs/for namespace:

shell command
git push origin HEAD:refs/for/main
Copied!

Workflow - work in progress

In case you want to push a "Work in progress", use the following instead:

shell command
git push origin HEAD:refs/for/main%wip
Copied!

You can also configure Gerrit to always mark your pushes as WIP. In order to do this head over to https://review.typo3.org/settings/ and configure "Set new changes" to "work in progress" by default".

See: https://gerrit-review.googlesource.com/Documentation/user-upload.html#wip

Workflow -other branches

Show all branches:

shell command
git branch -a
Copied!

Checkout 10.4 branch:

shell command
git checkout 10.4
Copied!

Checkout 9.5 branch:

shell command
git checkout 9.5
Copied!

Long story short: In most cases, push to main. The rest is being taken care of by core team members!

Push 10.4 branch:

shell command
git push origin HEAD:refs/for/10.4
Copied!

Push 9.5 branch:

shell command
git push origin HEAD:refs/for/9.5
Copied!

Workflow - commit msg

Details: Commit Message rules for TYPO3 CMS

Example commit message for a bugfix:

commit message
[BUGFIX] Subject line

Description

Resolves: #12345
Releases: main, 10.4
Copied!

Other keywords:

[BUGFIX]
[FEATURE]
[DOCS]
[TASK]
[!!!][FEATURE]
[WIP][TASK]
Copied!
  • subject < 52 chars
  • other lines <= 72 chars

Workflow - Undoing / fixing things

Throw away all changes since last commit:

shell command
git reset HEAD --hard
Copied!

Unstage a file (remove file from index, but keep in working dir):

shell command
git reset <path>
Copied!

Change author for last commit:

shell command
git commit --amend --author "Some Name <some@email>"
Copied!

Squash last 2 commits:

shell command
git rebase -i HEAD~2
Copied!

In the editor, replace 'pick' with 'squash' in the line describing the latest commit

This is very handy, in case you accidentally created a new commit instead of adding to an existing commit (with git commit --amend). This way, you can merge the last 2 commits and the commit messages.

References

See also these not TYPO3 specific cheat sheets for git if you are not very familiar with git:

To learn more about the internal working of Git, check out these resources: