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 Drupal.org account, click Edit, then Git access. Copy Git user configuration and paste it into Git Bash. Lines should look like this:

git config --global user.name "Your Name"
git config --global user.email you@example.com
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.

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

Linkified Git log messages for drupalcode.org and Issue queues.

A small shell function which linkifies git log output.
Modified from Ben Almans github version

  • drupalcode.org commit link
  • drupalcode.org blob links
  • drupal.org issue link if the commit message is formatted as Issue #123456

Example of linkified git log

Pages

Subscribe with RSS Subscribe to RSS - git