Tag Archives: git

Git 1.8.5 is out

Git 1.8.5 is now out. The RC was available for more than a month, and now it’s gone stable. One interesting change is the new alias for HEAD. From the atlassian blog:

This had been cooking for a while and it’s finally in: HEAD has a new alias, instead of typing four capital letters you can say “@” now, e.g. “git log @“.

Which means you can now just type in @^ for HEAD^ and @~2 for HEAD~2 and so on.

Among other notable changes are that git-repack (which was a shell script previously) has been rewritten in C, cherry-pick shows the commits being cherry-picked and diff-filter has got an “all-but” option.

Jenkins gets out of hot water

The Jenkins guys seem to have had a rough day.

yesterday something strange has happen to many Jenkins repositories on GitHub (more then 50 Repos)…
Luca Milanesio seems have pushed to many many repositories without really changing anything – at least I have not seen anything changed.

But the folks at github have helped by restoring the state prior to the force push into a separate branch. Good old git reflog to the rescue.

Typically recovering a force push is straightforward:
1. git reflog > look at the SHA-1 before the forced push
2. git branch -f <name> <sha-1>

As far as I know, bare repos don’t have reflog enabled by default. They might have turned on core.logAllRefUpdates for all the repos at github by default.

Don’t fork

The gist a simple git branching model has gained much popularity lately. The author mentions some drastic changes to the normal git flow like merging changes from feature branches straight into master. This is necessary to maintain simplicity.

There are some notes to the end of the gist. Among them is one titled “Don’t fork. Push feature branches to main repo.”.

Sometimes I see people forking repositories in order to issue pull-requests. Yes, you may have to do this when contributing to open-source projects you don’t regularly contribute to. But, if you are a contributor, or working in the same org, get push rights on the repo and push all your feature branches to it. Issue pull requests from one branch to another within the same repo.

Because the whole fork and pull-request mechanism can be devastating sometimes, you don’t need to consider such sophisticated schemes for small teams. Let’s face it, only a fraction developers out there have the itch to really learn the tools they are using. You’re lucky if more than half of your team is well-versed with at least the basic git commands.

When you can afford it, it’s always a good idea to have a central repo and give everyone write permissions. You can even fine-tune the permissions to specific branches if your git server runs gitolite. AFAIK, this is not possible with github or gitlab.

Github and Government

Git’s being used to do many more things besides version controlling code. I once wrote about tracking laws with git in Germany.

Github has introduced government.github.com. From their blog post:

Governments at all levels have been using GitHub for some time now to build better, more accessible websites, publish laws and data, and even collaborate on policies themselves.

Today we’re proud to announced the launch of government.github.com, a website dedicated to showcasing the amazing efforts of public servants and civic hackers around the globe.

Open data projects in github isn’t new. Concepts like forking your city shows the possibilities are boundless.

4b825dc642cb6eb9a060e54bf8d69288fbee4904

4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a special hash value in git which denotes an empty tree. And it does not change from repo to repo. This opens way to some neat tricks, but how the hell would one remember this value? You don’t need to.

Colin Schimmelfing:

In both of the links that mentioned the special hash, it looks like there is another way to find the magic value, a little faster:

> git hash-object -t tree –stdin < /dev/null
4b825dc642cb6eb9a060e54bf8d69288fbee4904

Thus you get the hash of the ‘null’ tree.

The author of the post mentions about changing/diff-ing the first commit using this, but remember that since git 1.7.12 or so you have this awesome –root flag for git-rebase which does wonders in this particularly intimidating situation.

So, if you want to amend the initial commit or add one after some commits (humans forget), you can just:

git rebase -i –root

Now just do whatever you want in the editor window that pops up. Anything’s possible with git-rebase.

Global Git ignore

I feel stupid for not being aware of a global git ignore earlier. It’s a good approach to globally ignore those editor-specific swap files, OS-specific crap (like .DS_Store in OS X) etc. From usevim:

A better approach is to use a global option. Run git config –global core.excludesfile ~/.gitignore. Then you can add *.sw?, and perhaps *~ as well. I like to add .DS_Store because Windows developers don’t need to worry about that nonsense, and they should probably add Thumbs.db.

The trick is to add globally-ignored files into some place like ~/.gitignore and specifying this in core.excludesfile.

Gitlab 6.0 is out

Just got to know that Gitlab 6.0 has been released over an week ago.

The biggest improvement I noticed in the changelog was the new merge request feature. You can fork a repo and send merge requests to the original – github style. Good news for everyone who kept away from Gitlab coz it’d break their workflows.

Some handy new features have found their way to the UI as well.

The groups still suck. They’ve continued to confuse me from the beginning. The flat structure would be okay for a small group of people, but if the organization is large (100+ developers) this can become a mess.

Also, let us organize the repos several sub-directories deep, please?

People here would know anyway

Seen in the #git freenode channel today:

circle : How do I find projects to work on in github?
bremner : fwiw, this is not a git question.
circle : true
circle : but people here would know any way

One wouldn’t go to #linux and ask them about a good keyboard to buy because everyone there use keyboards and are techy enough to know what keyboards are the best.

Forking and sex

From Quora:

Am I the only one who thinks the phrase “Fork me on GitHub” sounds like it has sexual implications?

This is a genuine question. I’ve asked several people what they thought about the phrase and not many feel the same way I do. I started to wonder if I was the only one.

Did I think it had sexual implications? Not until now. -_-

Keeping the Git directory and the working tree separate

When you clone/init a repo, the .git directory is created inside your working tree. This colleague of mine wanted to check-in the source code to a legacy versioning system other than git. Normally the .git directory gets pushed as well, since it’s inside the working tree.

Normal structure

But he didn’t want to push the .git dir as well. He wanted something like this:

Required structure

If you look at the git-clone man page, there’s this option called --separate-git-dir which lets you assign a custom directory as the .git dir. The syntax is:

git clone git://path.to.repo newdir --separate-git-dir=somedir

But in this case, my colleague didn’t want to clone again. He had local branches galore and all. So I tried out the git-clone mentioned above and checked what really happens. It turns out that git creates a file called .git inside the working tree that looks like this:

gitdir: /home/thameera/path/to/git/dir

Gotcha! Now what we need to do is move my friend’s .git directory to a separate location and create a file called .git that has the path to the git dir as above. It works!