Practical GIT and GitHub

GIT has many advantages over earlier systems such as CVS and Subversion (SVN), it is More efficient, and better workflow.
Many git tutorials and guides cover a lot of details make it hard to use as a practical guide.

You can find a lot of cheat sheets for git but again, if you are a beginner it will not help you.

The purpose of this guide is to go over the basic tasks we can do using git and github in a practical view

This guide is the first part – working on a project alone (one man show)

 

Installation

Download and install git from  https://git-scm.com – use the default settings

Open an account in github.com for remote git

 

Create a new project

  1. Go to github.com and create a new repository (start project)
  2. in git shell paste the following commands:
      
echo "# gittests" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/[your account]/gittests.git
git push -u origin master

Note: change the address to match your account

 

Working on the project

most of the time as a programmer you are doing this

  1. add files and directories
  2. Add the files to git and github using the following commands:
git add .                  # add the files to local git
git commit -m "msg"        # commit your changes to local git
git push -u origin master  # sync with remote git

 

 Creating a new version 

you want to test a new features for your project but not to break the current version – you need to create a branch and move to that branch

  1. create a new branch
  2. move to that branch
  3. add/change files
  4. commit and push (local and remote)
git branch b1
git checkout b1
# add or change files
git add .
git commit -m "b1"
git push -u origin b1

 

Working on your project with different versions:

now you can move from branch to branch and add/change anything you like just add and commit your changes to the local and remote repository:

git checkout [branch name]
# do changes
git add .
git commit -m "something"
git push -u origin [branch name]

you can move from brach to branch and do the above commands working with different versions

 

Merge changes from branch to branch

You can see the difference from other branch to the current branch using:

git diff [other branch name]

you can merge the branch changes to the master using:

git checkout master
git merge [branch name] # merge the changes
git add .
git commit -m "msg"     # update local repository 
git push origin master  # update remote repository

 

More useful command you can use anytime:

git status – see the current branch and status

git log – see the history

git revert – revert your changes

 

Next post – git in a team

 

 

 

 

Tagged