Working with git

Β· 309 words Β· 2 minute read

I won’t explain here how to clone the PostgreSQL repository. I assume you already know the basic usage of git as git pull, git add, git commit. If you don’t, please visit that website to download your free copy of Pro Git and read it.

In that post, I explained how to create a patch with git diff. Now we will learn how to apply that patch.

No pending changes πŸ”—

Be sure to have no pending changes before trying. That can be done with :

git status

If you have pending changes, you should know what it is. Either it’s a patch you’re writing and you can save it by creating a patch with your modifications then cleaning your git repo

patch p1 > pending_patches/patch_name_v0_x.patch
git reset --hard

either you did something wrong and don’t want to keep that changes :

git reset --hard

I know some guys like to git stash instead and I’m happy for them but my brain thinks it’s “too messy”. (Nothing rational here, just an impression.)

Be sure you’re on the latest version of master πŸ”—

First, you need to go to the master branch and update your repository.

git checkout master
git pull --rebase

You can perform a git status before, just to know if you have uncommitted changes.

Create a branch and apply πŸ”—

To keep your master branch clean without effort, you’ll certainly want to create a branch before applying:

git checkout -b name-of-your-choice
patch -p1 < your-patch-path

Then you should be able (or not) to compile your source code.

Drop your branch πŸ”—

Once you’re finished with testing your (or others) patch, you’ll need to destroy your branch :

git checkout master
git branch -D name-of-your-choice

Do you need more? πŸ”—

If you need more information, please look at the Postgres wiki pages :