7 Pro Tips For Using Git from Fedora Developers

130

Git hosts the scripts used in the the Fedora Project's release engineering.Back in 2010 a team of Fedora developers, lead by Jesse Keating, Toshio Kuratomi, and Clint Savage, converted the project from CVS to the Git revision control system.

Git is now deeply tied to Fedora’s package build workflow, says project leader Matthew Miller. Each of the nearly 20,000 packages in the distribution has it own Git repository – which together comprise the “dist git” collection of repositories for which about 1,600 people have some level of commit access.

“Every update to every package in Fedora goes through this system,” Miller said. “You can’t built something in Fedora without the spec file (which controls the RPM build) being in git, along with checksums of all source files (the source files themselves are stored in a lookaside cache).”

Git also hosts the scripts used in the project’s release engineering, Ansible playbooks, and the actual code for infrastructure applications, as well as many scattered applications such as Dockerfiles for Fedora Cloud.

Many of the project’s developers, then, are experienced Git users. In celebration of Git’s 10-year anniversary this month, we asked some of them to weigh in with their favorite pro tips for using the popular software development tool.

1. Garbage collection workaround

Miroslav Suchý: Sometimes git pull takes a long time. Sometimes git starts garbage collecting in a situation, where I was under time pressure. After this line in crontab I have no such problems any more:

40 3 * * * locate –regex /\.git$ | while read a; do ( cd $a; git fetch –all -t; git gc –aggressive; ) done

>/dev/null 2>/dev/null

2. History overview

Miroslav Suchý: And this in .gitconfig is a great way to quickly get an overview of history (credits goes to jesusr):

[alias]

lol = log –graph –decorate –pretty=oneline –abbrev-commit

3. Pick your push

Kevin Fenzi: Always run ‘git status’ and ‘git diff’ before commiting/pushing. That can show you when you have unrelated other changes you might not want to push.

4. Reverse mistakes

Paul Frields: If you make really bad mistakes, you can use ‘git reflog’ to reverse even egregious issues.

5. Re-focus your commits

Paul Frields: Also, ‘git rebase -i’ is great for times you forgot to keep your commits focused on the topic at hand. You can merge, split up, or edit diffs to make sure your commits are useful when you come back to them weeks or months later.

6. Cherry pick changes

Matthew Miller: Use ‘git cherry-pick’ to pull individual changes from a different branch. When I first switched to git, I would create diffs and apply them each by hand; then, when I discovered that there’s a much better way built-in, *mind blown*. In fact, I’d go so far as to generalize this: anytime you want to do something in git and it feels like the way you’re doing it is a bit awkward and clunky, take some time to look for a built-in feature which handles it better.

7: Manage team email

Matthew Miller: If your team does a lot of work via email, look at ‘git send-email’, which can take a range of commits and automatically post a nicely formatted series of messages to your list.

 

Read more Git anniversary stories:

How to Run Your Own Git Server

Git Success Stories and Tips from Wine Maintainer Alexandre Julliard

Git Success Stories and Tips from Puppet Labs’ Michael Stahnke

Git Success Stories and Tips from Tor Chief Architect Nick Mathewson

Git Success Stories and Tips from Drupal Core Committer Angie Byron

Git Success Stories and Tips from Qt Maintainer Thiago Macieira

Git Success Stories and Tips from KVM Maintainer Paolo Bonzini

10 Years of Git: An Interview with Git Creator Linus Torvalds