One of the best features of Git, which separates it from other version control systems, is distributed source control. A major pain point of earlier systems revolved around who was able to make changes – which can lead to lots of problems when working in a team. Git’s approach provides everyone with his or her own repository, so that problem largely goes away.

Fun fact: Git is a term of insult with origins in British English denoting an unpleasant, silly, incompetent, stupid, annoying, senile, elderly or childish person. Linus Torvalds used the word in a self-deprecating manner when choosing a name for the system.

I didn’t know the origin of the system’s name prior to writing this post. It makes my reference to Idiocracy in the last post seem completely appropriate.

OK, let’s get started! Today, we’ll create a new repository at Github and push our existing, local, repository to it. If you don’t have the repository we created in the last post, or are just getting started, now is a good time to read Getting Started With Git.

First things first – if you don’t already have a Github account, create one and then follow the instructions to create a new repository. Don’t add anything (this includes the optional readme and other files Github will offer to create) for now since we’ll be pushing an existing repository.

I’ve gone ahead and created a repo named “getting-started” in Valiant’s Github account. Once created, I use the git remote add command and then pushed my repository to Github with the git push command:

Pushing repo changes.

OK, let’s break down those 2 commands:

The git remote add command allows us to add a remote repository. The first argument is a remote name, and the second is a remote URL – in this case, the URL of the Github repository.

The git push command sends the contents of your local repository to the remote that was defined by the last command. We use the –u flag to add a tracking reference to the upstream server we are pushing to. This just means that we won’t have to specify the remote name or branch. The next time you need to push from your local repository to the remote, simply use the git push command without any arguments:

Push to remote repository.

After pushing the latest set of changes in my local repo to Github, I noticed that I made a bit of a mistake! I meant to name the readme file from the earlier example “readme.md” and not “readme.txt” so I went ahead and renamed the file, committed the changes and pushed to Github again:

Pushing recent changes to remote repository.

If you’d like to take a look at the repository used in this post, click here.
Mistakes like this happen, and can lead to larger problems when you are collaborating with multiple people on a project. Yep, we’re almost ready to talk about branching. We’ll save that for the next post. Till next time!