GIT – BASICS – João Costa



GIT – BASICS – João Costa

0 0


git-basics

Workshop on git basics

On Github cesium / git-basics

GIT

BASICS

João Costa

Martinho Aragão

What is

Version Control?

What is it good for? Why do I need it?

Routine

void routine() {
  create;

  while(!over){
    edit;
    save;
  }
}

Remote

What happened?

Why did it happen?

Who did it?

When?

Commits

Installing Git

Linux

Debian/Ubuntu
$ apt-get install git
Arch
$ pacman -S git
Fedora
$ yum install git

Mac

brew install git

Windows

Download

Git Setup

First-Time

Setup your username and email first of all to give you credit for the code you are developing.

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

See configuration

$ git config --list

Creating a Git Repository

$ git init
            
path
                
will create new directory if needed

Initialises a .git directory in your folder

Git Staging

The Three States

Your files can have three states:

Modified Staged Commited

1. Working Directory

These are the files that are under Git control and are unstaged.

2. The Staging Area

Seeing file status:

$ git status
After you've done your changes, you can stage files with:
$ git add <filename> (Add files)
$ git add --all (To add all files)
An example:
$ git add git.c git.h
These files you added to the staging area will be commited to your local database.

3. Commiting

After adding all the files you wish to commit just run:

$ git commit
Some examples:
$ git commit -m "Add slide about pushing to a repository"
Your data is now safely stored on your local database.

See all commits

$ git log
Quit with 'q'

Branches

Why Branches?

Branching

To create a branch

$ git branch test
To change branch
$ git checkout test
Or better yet!
$ git checkout -b test

Listing all branchs

$ git branch

MERGING

Merging

Do it when you have finished working on your feature, bug fix, etc.

Change to the branch you wish to merge your work
$ git checkout <branch-name>
Merge the changes
$ git merge <branch-name>

An example
$ git checkout master
$ git merge test

Your turn now

Working Remote

Signup for a Github account

BitBucket

Clone

$ git clone <address>

Pushing

All commits done? Want to share what you've done?

$ git push origin <branch name>

An example:
$ git push -u origin master

Pulling

Need to grab what the others did? This is when to use push.

$ git pull origin <branch name>

An example:
$ git pull -u origin master
$ git pull 

Wanna learn more?

Getting Help

$ git help 
$ git  --help
$ man git 

Example: Checking config help

$ git help config

Git Documentation

Documentation

GUI Clients

MAC

Download

Windows

Download

All GUI clients

There are also other GUIs created by people outside Github. There is a full list with download links here.

GIT BASICS