Git for beginners

My first experiences with version control system were rather troublesome. I was introduced to Apache Subversion in a way that has not really worked for me, so it took me a while to get even the simplest basics of using it and I have abandoned the whole thing straight after the associated task was done. I thought, I have managed without it before, so I will be just fine. There are two problems. Firstly, an efficient cooperation in software development without it is really hard, if possible at all. And secondly, have you spot recently a single job add for software developer without it in the requirements? Even if, it is just because that position in developer’s toolkit is so obvious that not even worth mentioning. Like it or not, you have to learn it, I told myself. And here I am, learning Git and writing this little how-to along the way. Why Git? As I said, bad experience with SVN, but also popularity of Git and a student account with free private repositories (normally a paid option) on GitHub that I created two years ago and never used. So, let’s start.

Initial setup

If your operating system is other than some distribution of GNU/Linux, you have to figure out the details specific for your OS, sorry, homework required. To get Git it is best to go to the source, that is the download page at GNU/Linux users should check their distro repository. I would be surprised if Git is not available for installation that way.

So, you have installed Git. Now GitHub. Creating an account over there is very intuitive, so I will not be getting into details here (if there is any problem, here is a great help provided by GitHub itself). However, what I would suggest is to generate a personal access token for the command line. It makes life easier. Here are details how to do that. After you generate your token, add it manually to the .gitconfig file or, better, use a command line (by the way, we will use the command line a lot, so get used to it if you are not already):

git config --global github.user YourGitHubUserName
git config --global github.token YourGitHubToken

OK, this part is done. Time for

Your first repository

First, create a new repository on your GitHub. Next, create a working directory on your computer for your project, go to it and initialize a local git repository:

mkdir -p ~/YourProject/Working/Directory
cd ~/YourProject/Working/Directory
git init

Then add the GitHub repository and check if everything is fine:

git remote add origin
git remote -v

You should see something like that:

origin (fetch)
origin (push)

If you have followed the how-to for repository creation, your GitHub repo probably already contains and LICENCE files. To avoid problems first fetch from and integrate your local repository that is in your working directory with the GitHub repository:

git pull origin master

Now it is time to actually add some code, so either start creating files with code in the working directory or move some there from whatever location you kept them so far. When it is done, check the status of your local repository:

git status

You should see something like this:

On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)


nothing added to commit but untracked files present (use "git add" to track)

So, it is time to add those files and commit changes to the local repository:

git add --all
git commit --all -m "Initial commit"

You should see something like this:

[master (root-commit) 99348f7] Initial commit
 Committer: Maciej Modzelewski <user@computer.home>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global "Your Name"
    git config --global

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 4 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 code1.php
 create mode 100644 code2.php
 create mode 100644 index.php
 create mode 100644 testing.php

And now the last step, pushing changes to the GitHub repository:

git push origin master

That is pretty much all for the beginning. At least this is as far as I have managed to get so far. What I could add is that it is probably a good idea to have a look at these GitHub guides. I have not yet found time for that, but I am going to read them as soon as possible.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.