User:Aude/Git

Clone
git clone ssh://aude@gerrit.wikimedia.org:29418/mediawiki/core.git mediawiki

Clone a specific tag or branch of a git repo:

git clone --branch 0.16.0 https://github.com/wikimedia/data-values-value-view.git

Checkout
Checkout version from a specific date or point in time:

or:

git checkout 'master@{2013-09-19 12:00:00}'

Config
Set global configuration, if only or primarily doing Wikimedia development: git config --global user.name 'aude' git config --global user.email 'my.email@gmail.com'

It is important for the email to match your email set in Gerrit, and the name is less important.

Set configuration for individual git repositories: git config --local user.name 'aude' git config --local user.email 'my.email@gmail.com'

View global config: git config --global -l

View local config: git config --local -l

If git or gerrit complain about the committer not matching, check the config, and you can also check how your commits are credited:

To commit stuff
git commit -a

This will bring up your text editor where you can enter a commit summary.

You can configure which text editor to use with the export command or add it to your ~/.bash_profile file.

or specify in git config:

git config --global core.editor "vim"

Using the text editor to provide more detailed commit summary is better, however it is also possible to provide the commit summary as an argument in the commit command:

git commit -a -m 'blah blah blah'

Stash
git stash save 'blah blah'

Update local code
in the morning, do:

git pull --rebase origin master

Submit code for review
Sanity check, make sure you are on the correct branch, etc.

git status nothing to commit (working directory clean)
 * 1) On branch coolnewfeature

See what you are about to submit:

git show HEAD commit e08067e92aa72d9bf5a740e1933469f4d249df96 Author: aude  Date: Sat Jan 5 17:25:33 2013 +0000

add README Change-Id: I4ff31405425e27b974d44aabb78d5c3538db92cc Signed-off-by: aude 

Instead of git push origin, use git review to submit your change to gerrit:

git review

Branching
Make a local branch:

Create a branch based on a commit hash:

Checkout a remote branch into a local branch:

Make some changes, commit them and push to review.

Create a new remote branch
If needed, gerrit remote needs to be added:

List branches
List remote branches:

List all branches:

See current remote branches:

Get details for a remote:

Deleting branches
To batch delete (wildcard) branches:

or to force delete branches with "not fully merged" stuff:

To delete remote branches, such as on github, where one might have permission to do so:

To batch delete remote branches:

Remove untracked files / clean
Removes directories and files:

Bash prompt
Display the git branch in the bash prompt, the following can be added to your ~/.bashrc file. To make the change take effect, then

When were the branches last modified?
See a list of all branches sorted by last modified date:

Works on windows, mac or linux, but not as pretty:

Tags

 * note, it might be "origin" instead of gerrit.
 * if the remote is not recognized, then it needs to be added per User:Aude/Git

Removing files from a repo
To recursively remove a folder and files from a repo:

Reset
or

To unstage files (e.g., after git add -A):

View log
Just a plain git log, with details:

Create a patch
From the master branch:

make a bunch of changes

Revert
Revert a specific commit:

Revert a merge commit (with  or   depending on which parent branch to revert back to):

Amend specific commit in series of patches
In interactive mode, then:

Then make changes, and then:

Squash a commit
In interactive mode, then:

Edit the commit message, then save and then git will combine the two commits into a single commit.

If amending and resubmitting to gerrit, then.

Merge conflicts
or set it:

Merge in subsequent commits into a patch
When you have resolved this problem run "git rebase --continue".

Submodules
Checkout wmf core branch and extension submodules:

If renaming the core directory, references to the submodules need to be updated.

In core/extensions:

in core/.git:


 * Removing submodules
 * http://davidwalsh.name/git-remove-submodule


 * See also
 * wikitech:How to deploy code

Split subpath
To split subdirectories of a git repo into separate repos:

Create clone copies and then in the clone:

Git blame and credits
Get number of commits per author for a file:

Get number of lines per author, based on git blame:

Number of commits by author:

Get a list of projects
In the shell:

Or go to https://gerrit.wikimedia.org/r/#/admin/projects/

Improving a patch
make some changes

Adding a dependency
If you need to amend your patch to have the correct dependency:


 * 1) Resolve conflicts if needed,
 * 2) - use "git status" to see the files that need resolution
 * 3) - after fixing it in your editor, "git add filename" for each of the fixed files

The git push directly will make sure that the dependency is kept and the other revisions that are already in gerrit will not be re-submitted.

Fix a dependency
Change a commit to a new patchset, such as 5a05e0e (5a05e0ef437278eff23c5a8b076b91f0cc7541c8) to cbcd5a0 (cbcd5a08c895d038a3ca7dc10e8d94806e2cae10).

Re-commit your patch replacing the one with the wrong parent

Resubmit to gerrit:

Import github repo into existing empty gerrit repo

 * https://www.assembla.com/spaces/breakoutdocs/wiki/MigrateGitToGerrit

Keyboard shortcuts
Gerrit has keyboard shortcuts. A list of shortcuts can be displayed by clicking "?".

Deployment stuff

 * Each deployment, if extensions not at master:
 * https://gerrit.wikimedia.org/r/#/c/37301/ -- mediawiki/tools/release, make-wmf-branch/default.conf (update commit points, if not master)


 * For new extensions
 * wikitech:How_to_deploy_code
 * https://gerrit.wikimedia.org/r/#/c/37047/ (new extension)
 * https://gerrit.wikimedia.org/r/#/c/37046/ (for new extension)