Troubleshooting 'git checkout'

I've got a "You are on a branch yet to be born" error in a new repository
This is a common issue in older versions of Git, where you need to have a commit in order to switch branches. You'll need to make your initial commit to master, then switch to your version branch (7.x-1.x) and push that (git push origin 7.x-1.x). Once you've switched branches, you can delete the master branch from your local repository.

You can also use git branch -m master 7.x-1.x to rename the branch, if that's supported in the version that you're running.

Getting started with Git (for Drupal) on Windows

New to Git? Take a look at Introduction to Git.

Install Git on your local machine

Download Git for Windows. Follow the link Download for Windows.

Install using default settings only.

Add Git Bash to the Taskbar. Open Start menu and type git. Right-click Git Bash then click Pin this program to the taskbar. In taskbar, right-click Git Bash icon, then right-click Git Bash, then click Properties.

  • Shortcut tab: Set the Start in option to your local server's root directory (e.g c:\xampp\htdocs)
  • Options tab: set Buffer Size to 500 or something large (Buffer size is number of lines for scrollbar to go back), check Quick Edit checkbox.
  • Click OK to close Properties dialog.

Configure git user. Open your account, click Edit, then Git access. Copy Git user configuration and paste it into Git Bash. Lines should look like this:

git config --global "Your Name"
git config --global
git config --global core.autocrlf true

Hands-on: Hook up with an GIT repository

For git you need the "GIT backend" module.

Here is an example of using GIT backend:

Step 1: create an bare GIT repository (skip this if you already have one)

mkdir bare.git
cd bare.git
git init --bare

Step 2: set up your Drupal site with that repository

  1. Enable the "Version Control API", "Commit Log" and "GIT backend" modules.
  2. Flush cache.
  3. Assign role permissions for for "Administer version control systems"
    (by default nobody has any permissions)
  4. Go to Configuration > Development > Version Control settings (url: /admin/config/development/versioncontrol-settings)
  5. Set "Git binary path". (Notice: Can be problems with Windows OS. On *nix OS there are no problems with path)
  6. Go to Content > VCS repositories > Add Git repository in the admin area. (url: /admin/content/versioncontrol-repositories/add-git)
  7. Repository name: "Test repo", or whatever.
  8. Repository root: "/path/to/repository/bare.git".
  9. For other settings follow fields descriptions(and check "Web viewer URL handler" because by default it's not set. Might it'll be fixed in closest time)
  10. Save the repository.
  11. Enable the "Commit messages" menu entry, or go directly to the "/commitlog" path.

Using git blame

The git blame command can be used to determine when a certain change was made. This document will explain how to use this functionality in the terminal and in Drupal's git repository browser at

How to work on a patch that is not yet in core, but is needed as base cleanly

For twig we had the problem that the basic patch was not accepted, but that the followup issues should be clean.

The idea is to use two patches within one.

What do you do if you happen to find a patch with two patches in one?

Patch contributors

For patch contributors the workflow is not that difficult to the regular patches:

Assuming origin is the "core" repository and you work in feature branches the workflow is:

Lets further assume the patch is in issue 1806546 with comment number 4

Getting a clean branch:

# update core
git fetch origin
# checkout 8.x branch
git checkout origin/8.x
# checking out an issue feature branch with comment number
git checkout -b core-1806546-4

Applying the current patch:

wget .../patch.diff
# this directly _commits_ the patches, conflicts are resolved like
# with rebase / merge
git am patch.diff
# Now you fork again with your new comment number
git checkout -b core-1806546-5

Now you add your changes and then you do:

# this updates the original patch and can be done as often as you want
git commit --amend .
# this creates the new 2-part patch
git format-patch -M --stdout origin/8.x > mynewpatch.diff
# this creates the interdiff
git format-patch -M --stdout core-1806546-4 > interdiff.txt


Subscribe with RSS Subscribe to RSS - git