Section D: Git basics
After git is installed you should setup a couple of setting
git config --global user.name ""
git config --global user.email ""
Try not to think of git as a complex program but as many simple programs rolled into one, each with there own purpose. Almost all of Git's commands are prefixed by.... you guessed it, $git.
So to start of lets get an already created git repository or git repo.
$ git clone
[email protected]:linuxmotion/GitGuides.git
This shell command means invoke the git command and create a git repo called GitGuides
using the information from the url to grab the data. This is the most basic of commands. Optionally you can specify the directory to clone into is called by adding it after the URL.
$ git clone
[email protected]:linuxmotion/GitGuides.git Guides
Now lets say you whant to create a new git repo from scratch. We create a new clean git directory by first creating a empty directory. After the directory is created we will then initialize the repo.
$ mkdir
$ cd
$ git init
Now that the repo is initialized we can add some files to repository. We add files to git repository by first creating a file then using 'git add '. Here I am telling git to include all the files the are in the current working directory, optionally you can individually specify which files to inlcude.
$ touch README
$ git add .
Or
$ git add
Once the files are added we can then 'commit' them to the repo. 'Committing' means that we want to include that file in the repository and track the changes that are made to that file. Commits are the saved state of the repo. Commits take a message that allows them to be looked over with a title and message so that users can tell what has happened. If 'git commit' is used without passing the -m flag, or message flag, the default text editor will be brought up to prepare a message for the commit.
$ git commit
or
$ git commit -m''
Now that we have created the git repository and commited some files we can now upload or 'push' the changes to a semi-central location github.com. Assuming that you used github.com to create the repoistory to push to and is the repo is called GitGuides then the URL I would use is
[email protected]:linuxmotion/GitGuides.git. First to push to a location you will have to add a remote, or a place to download/upload changes from.
$ git remote add origin
[email protected]:linuxmotion/GitGuides.git
$ git push origin master
Optionally you specify what branch that 'git push' will push to without arguments by specifying the upstream branch to track with. From the current branch we issue the set-upstream subcommand. Since we are on the master branch this set the master branch to track the master branch from the remote.
$ git branch --set-upstream master origin/master
With the upstream set we can now push the changes to github using if the branch is created in the upstream repo, otherwise you must use 'git push '
$ git push
Now you may be asking why you didnt have to add the remote when you cloned the first repo. Well when you clone a repository using git clone, a tracking branch is set up automatically called master that tracks origin/master.
There you go, now you can get a already created repo, create a repo yourself and you can push changes to the repo. You may be wondering, 'How do I get changes from others that commited on the project'. Since that can be a little more tricky it will be covered in the next section