This blog post seeks to answer these 2 questions about Git
Firstly, Git - Why bother?Secondly, What is the absolute minimum anyone needs to know in order to make Git useful for a team of one?
It is inspired by the Mezzanine blog posts of Ross Laird and the examples will use the terminal on Ubuntu 14.04 and the web site http://github.com
Git - Why bother?
Git helps you manage the complexity of software development.The key way it helps me is that it creates discipline.
One small change = one commit. Keeps things going slowly and steadily because if you rush and change too much code you can't usefully summarise what you have done for the commit message!
Git helps you learn as you develop and recall the learning.
Each problem you solve is recorded (providing you commit often, which I would recommend) and using github you are able to recall what you did to solve your problem, long after it has slipped from memory.
Git enables co-operation.
Once your GIT skills have improved you will be able to co-operate with others and help to produce great open-source software!
What is the absolute minimum anyone needs to know in order to make Git useful for a team of one?
# 1- Sign up for github at http://github.com
Pick a short username and a minimum length password (7 letters) because you will be typing them every time you do a commit.
# 2 - Install Git on your computer
Start the terminal and type insudo apt-get updateType in your computer password (if you are asked for it)
When this has stopped running type in
sudo apt-get install gitWhen this has stopped running you should have installed git
# 3 - Check you can use these 5 basic commands necessary to navigate the terminal
pwd - where am I?ls - what files and child directories are here?cd- take me to my home directory (from anywhere)cd .. - take me up to the parent directorycd 'a child directory' - take me down to a child directory # 4 - Set up Git with the basics
To get going with Git there are 3 basic bits of information you need to tell Git about. Using the Terminal again, type the following (include the ")git config --global user.name "Your github username from # 1"git config --global user.email "Your github email address from # 1"git config --global core.editor "nano -w"The final command will set Git up to use the text editor 'nano' to write your commit messages. It is simple to use and keeps you in the terminal when writing your commit messages (see below).
# 5 - Familiarise yourself with this 'Super Simple' Git workflow
A diagram that is often praised when looking at how Git works was produced by Oliver Steele.I have taken that diagram and stripped it down to this 'Super Simple' minimum.

The 'remote repository' will be on the github account we created in #1
The 'workspace' will be a directory of our choosing on our own computer
I think of the 'local repository' as more of a 'state' than a place
There are two basic ways to get started using Git, they are set out below. in #6 and #7.
# 6 - Get started - workspace first
From any directory, type the following command in the Terminalgit status... leading to this response
'fatal: Not a git repository (or any of the parent directories): .git'Despite appearances this is not at all 'fatal', it simply means that Git is asleep and needs to be woken up.
cdmkdir git-workspacecd git-workspacegit init... leading to this response
Initialized empty Git repository in /home/graham/git-workspace/.git/
git statusOn branch master Initial commit nothing to commit (create/copy files and use "git add" to track)Git is now awake and waiting for files. So, lets create an empty file...
touch my-first-git-file.txtgit statusOn branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
my-first-git-file.txt
nothing added to commit but untracked files present (use "git add" to track)
Git is suggesting we 'use "git add" to track' so let's take the advice...git add my-first-git-file.txtgit statusOn branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: my-first-git-file.txt
Git is showing us 'Changes to be committed', so its time to do our first commit...git commit -aGit starts 'nano', the text editor that we configured in #4 and you should see something like this...

Enter your commit message, in my case 'My first super simple commit'
Press 'Ctrl-X'
Then save your commit message by entering 'Y' and 'Enter'
[master (root-commit) bc56965] My first super simple commit 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 my-first-git-file.txt
The 'local repository' is now up to date and we now need to push its contents to the 'remote repository' on github.
Before we can do that we must create the remote repository on github and obtain its URL.
Go to https://github.com/new and enter the name of your repository and nothing else.
Then click 'Create Repository'
The URL of the remote repository on github is given to us at the top of the resulting page (your username will probably not be 'poopernut'!)

First connect our 'local respository' to our 'remote repository' as follows
git remote add origin "URL of the remote repository on github"Then push the 'local repository' to the 'remote repository'
git push origin masterEnter your username and password from #1 and you are done.
Have a look at what you have created on github whilst savouring a cup of coffee!
# 7 - Get started - remote respository first
Search for a github project that you like the look of. I will use MezzanineFrom the home page of the github project you have chosen, stay calm and click on 'Fork'. (don't worry you can't do any harm!)
Now we need the URL of your remote repository which can be found here

Go back to the Terminal and type
cdgit clone "the URL of your remote repository"Cloning into 'mezzanine'... remote: Counting objects: 43420, done. remote: Total 43420 (delta 0), reused 1 (delta 0) Receiving objects: 100% (43420/43420), 39.30 MiB | 3.07 MiB/s, done. Resolving deltas: 100% (23782/23782), done. Checking connectivity... done.The Mezzanine files have arrived on your computer
cd mezzaninegit statusOn branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working directory cleanTime for another cup of coffee!
No comments:
Post a Comment