ryanwold.net

A civic-minded citizen seeking the singularity

Back to Entries

Programming Notes: Using Git for the first time

idea
Date: 2013-08-25
Tags: git notes programming

Developing one-off applications is quite different from developing robust applications as part of a team. As an individual, the complexity of a development environment is readily contained a developer's head and many devices. For a one-off, the success of a piece is that it gets the job done, and that job is typically confined to a small user base across a known set of devices and platforms. Real applications require an entirely new set of considerations, such as testing (Unit and Functional) and scripted and automated deployments.

Contributing to a shared repository of code requires adherence to some of the social niceties of team development; name using Source Control. I'd read about Subversion and even used a Windows implementation of it to version files. Yet, I knew Sunlight used Github to track lots (if not all) its source, so I thought I'd get familar with it before heading out there for the Summer.

Most 'git' tutorials start with the command line, which can be a pain in Windows. But mSysGit is available for Windows, which is a Cygwin shell along with Git tools.

Initially, I was initimidated with a command line interface to manages all my files (and versions thereof). Hey, I'm from Windows... I want a GUI. As a Rails developer, this is almost blasphemous, so I decided to hedge my bets by running Ubuntu (now at 10.04) as well. GitG is available for Ubuntu which as a GUI, but installing Git was as easy as 'apt-get install git'. GitG appears to be close to Mac's GitX. In time, also found "SmartGit" for Windows, which provides a nice, similar interface that I found actually helps with understanding some of the basic Git concepts of init, push, pull, fetch, merge, branch.

Neverthless, I felt I should learn Git the "real way", which of course, is from the command line.

To Start, I ran a few commands to configure the basics of Git.

git config --global user.name "Ryan Wold" git config --global user.email wold@afomi.com git config --global color.ui true

Use "git init" from an existing directory to initialize the directory as a Git project. Follow "git init" with "git add ." to add all files recursively to the project. (Git allows you to specify exactly which files you want included in a project, so you don't have to add all files, but then you'd have to add the ones you wanted to include manually. Git also allows you to "ignore" files, directories, or file extensions, so you could add all files, then ignore a few selected configuration files.

Git has the concept of Branches, which are independent repositories of code. Some names of example branches are "Master", "Test", "Test-Feature", etc. "Master" is a Git default, and it should typically contain the latest, verified versions of code. Following that convention, "Test" or "Dev" branches are often used to write code that is in progress. Once a "Dev" branch is deemed ready for production, it can be "merged" into "Master", which adds or overwrites the files to the "Master" branch.

The basic Git workflow is like this:

Initiate a project Add files to the project Stage files Commit files to a (local) repository "Push" files to an origin (ie: to Github.com)

--

"Fetch" grabs some files and brings them back. "Merge" merges some files into a specified branch. "Pull" fetches some files, then merges them into a specified branch.

Use "git clone " to clone a project. For example, "git clone git://github.com/afomi/project-name.git" will clone a project into a local directory, from where can then be worked on, you can submit a "Pull Request", asking a fellow author to consider accepting your proposed (and unit-tested) code.

Sources:

http://progit.org/book/ http://book.git-scm.com/ http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html

By Ryan Wold · © 2013–2026 Ryan Wold

Licensed CC BY-NC 4.0. AI training requires a license — machine-readable terms.

Tip: $afomi on HandCash · afomi@handcash.io