0% found this document useful (0 votes)
45 views6 pages

Ruby Specialisation: Siddhant Pyasi June 3, 2017

This document provides an overview of using Git for version control. It discusses setting up Git locally and initializing repositories by creating new ones or cloning existing ones. It describes the basic Git workflow including adding, committing, and pushing changes. It also covers reverting and diffing changes as well as linking repositories to remote servers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views6 pages

Ruby Specialisation: Siddhant Pyasi June 3, 2017

This document provides an overview of using Git for version control. It discusses setting up Git locally and initializing repositories by creating new ones or cloning existing ones. It describes the basic Git workflow including adding, committing, and pushing changes. It also covers reverting and diffing changes as well as linking repositories to remote servers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Ruby Specialisation

Siddhant Pyasi
June 3, 2017

i
Contents
1 Git 1
1.1 Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Initialising a Repository . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.1 Create a new repository . . . . . . . . . . . . . . . . . . . 3
1.2.2 Clone an existing repository . . . . . . . . . . . . . . . . . 3
1.3 Working on a repository . . . . . . . . . . . . . . . . . . . . . . . 3
1.3.1 Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3.2 Add . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3.3 Di . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3.4 Commit . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3.5 Reverting changes . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Remote Repositories . . . . . . . . . . . . . . . . . . . . . . . . . 4

ii
1 Git
Git is a Version Control System (VCS), that keeps track of changes made to files.
There are two main kinds of VCS:

Centralised Examples are the Concurrent Versions System (CVS) and Subver-
sion.

1. The repository resides on a central server


2. The client has a version of the trunk or branch.

Distributed Examples are Git and Mercurial

1. The entire repository resides locally


2. The full history of all the changes is contained in it
3. The server is mostly not involved
4. You can push and pull changes between repositories
5. Backups are readily available

The flowchart below describes the general workflow of Git:


Create/Clone repo

Add changes to staging area

Commit changes (from staging area to local repo)

Push changes from local to remote repo

The following image further clarifies the workflow of Git

1
Here are a few resources/references for Git:

1. Gits ocial website.

2. A free Git book is available here.

3. Another good git reference can be found here.

1.1 Setup
To set up properties globally, use the following commands:
$git config --global user.name El Sid Campeador
$git config --global user.email [email protected]

To verify that an option has been set:


$git config <option> $git config user.name

For getting help on any Git command:


$git help <command>

1.2 Initialising a Repository


You could either:

1. Create a new repository

2. Clone a repository

2
1.2.1 Create a new repository
$cd workingDirectory
$git init
$git add .
$git commit -m Initial commit

1.2.2 Clone an existing repository


$cd workingDirectory
$git init
$git add .
$git commit -m Initial commit

1.3 Working on a repository


1.3.1 Status
This command provides the current status of the repository
$git status

1.3.2 Add
This adds:
1. untracked files to be tracked
2. modified tracked file to the staging area
$git add <file/dir>

1.3.3 Diff
There are three kinds of commands here, as shown below.
The first one shows the dierence between staging and working directory:

$git diff

The second one show the changes between HEAD (which is the latest commit
on the current branch) and the staging directory:
$git diff --staged

This one shows the deltas/changes between HEAD and the working directory:
$git diff HEAD

3
1.3.4 Commit
This commits your changes to the repo:
$git commit -m Your message here

To skip the staging area, just type:


$git commit -am Your message here

1.3.5 Reverting changes


You can reverse the changes either:

1. Before Committing
$git checkout . (This is to reverse the status of all files overwriting
local changes)
$git checkout -- <file> (This is to reverse just one file)

2. After Committing
$git revert HEAD (Reverts the most recent commit)

1.4 Remote Repositories


To link a remote repo with your local repo:
$git remote add alias remote_url

The default alias for a cloned repo is origin. To push changes to your branch

out:
$git push alias branch_name

You might also like