These are the Git commands I find myself using the most while working on my OPW project, and what they mean. This post is mostly for my reference, so I don’t have to keep looking up the same things in Wikimedia’s Gerrit Tutorial, and in the Git book.
Update my local master branch
This updates my local master branch so that it’s the same as origin (the remote that it was cloned from). Git pull fetches any new commits from the remote, and merges them into the local master branch. The merge involves ”fast-forwarding,” which means the pointer in my local master branch is moved to the latest fetched commit.
Create a new branch
Here co is an alias for checkout, and the command is short for:
Git branch MyNewBranchName creates a new branch named ‘MyNewBranchName.’ And –track origin/master sets up a push/pull relationship with the origin/master branch. This means that when I use the push or pull command on my new branch, I’ll be pushing or pulling to the master branch of the remote my repo was cloned from. Finally, git checkout switches me to my new branch.
Check and commit changes
tells me which files I’ve added or modified since the last commit.
shows me how I’ve modified the modified files, and points out trailing/extra whitespace.
tells Git to commit changes to the file named ‘FILENAME’ in the next commit. And
makes a commit.
Synch up with remote
While I’ve been working on my new branch, others may have pushed changes to the remote. git pull –rebase fetches new commits from the remote, and replays them on my local branch. Here’s how it works:
It works by going to the common ancestor of the two branches (the one you’re on and the one you’re rebasing onto), getting the diff introduced by each commit of the branch you’re on, saving those diffs to temporary files, resetting the current branch to the same commit as the branch you are rebasing onto, and finally applying each change in turn.
Make a patch
This pushes changes to Gerrit, the code review tool that Wikimedia uses.
Alter the patch
If I want to change the patch I’ve pushed to Gerrit (say, after code review), I can continue working on the branch MyNewBranchName and proceed as above except committing with –amend:
Delete the branch
Once my patch has been merged in, I delete the branch, ‘MyNewBranchName,’ that I was working on:
Some mysteries (for now)
Reminders to look into these things I don’t understand yet:
How does git review -R work?
Rather than git pull –rebase above, the Gerrit tutorial tells me to use
I’m not sure how this is different, and why I get an error message along the lines of
when I do this, but not with git pull –rebase.