0 ratings0% found this document useful (0 votes) 375 views36 pagesGit Workshop - PDF Version 1-Rotated
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
git / git hub
WORK SHOP
BY
Mr.NATARAJ Sir
Ni” NARESH
technologies
9901 2008 Certined CompanyNaresh i Technologies By Mr.Nataraj
Introduction
Git is a distributed revision control and source code management system with an
emphasis on speed. Git was initially designed and developed by Linus Torvaldsfor
Linux kernel development. Git isa free softwareThis Document explains how to use Git
for project version control in a distributedenvironment while working on web-based
and non-web-based applications development
About the Document
Tris Document will help beginners learn the basic functionality of Git version control
system. After completing this document, you will find yourseti at a moderate level of
expertise in using Git version control system from where you can take yourself to the
nextlevels,
Prerequisites
We assume that you are going to use Git to handle all levels of Java and non-
Java projects. So, it will be good ifyou havesome amount of exposure to
software development life cycle and working knowledge of developing web based
and non-web-based applications.
GIT VS SVN
1. GIT is distributed, SVN is not:
‘This is by far the *core* difference between GIT and other non-distributed version
control systems like SVN, CVS etc. If you can catch this concept well, then you have
crossed half the bridge. To add a disclaimer, GIT is not the first or only distribu:ed
Ves(version control system) currently available. There are other tools
like Bitkeeper, Mercurial etc. which also work on distributed mode. But, GIT does it
better and comes with much more powerful features.
GIT like SVN do have centralized repository or server. But, GIT is more intendec to
be used in distributed mode which means, every developer checking out code from
central repository/server will have their own cloned repository installed on theit
machine. Let's say if you are stuck somewhere where you don’t have network
connectivity, like inside the flight, basement, elevator etc. :}, you will still be able to
commit files, look at revision history, create branches etc. This may sound trivialNaresh i Technologies By MrNataraj
for lot of people but, itis a big deal when you often bump into no-network scenario,
And also, the distributed mode of operation is a biggest blessing for oper-source
software development communi. Instead of creating patches & sending it through
emails, you can create a branch & send a pull request to the project team. It will
help the cade stay streamlined without getting lost in transport. GitHub.com is an
awesome working example of that-There were some rumors that the future version
of subversion will be working on distributed mode. But, it's still an unknown at this,
point.
2. GIT stores content as metadata, SVN stores just files:
Every source control systems stores the metadata of files in hidden folders like svn,
.ovs otc., whereas GIT stores entire content inside the git folder. you compare the
size of git older with svn, you will notice a big difference. So, the git folder is the
cloned repository in your machine, it has everything that the central repost:ory has
like tags, branches, version histories etc.
¥
GIT branches are not the same as SVN branches:
Branches in SVN are nothing but just another folder inthe repository. Iryouneed to
know if you had merged a branch, you need to explicitly run commands to verify if
it was me-ged or notSo, the chance of adding up orphan branches is pretty
big Whereas, working with GIT branches is much easier & fun. You can quickly
switch between branches from the same working drectory. It helps fincing un-
merged branches and also help merging files fairly easily & quickly.
4, GIT doesnot have a global revision no. like SVN d
This is one of the biggest feature I miss in GIT from SVN so far. As you mey know
already SVW's revision no. is a snapshot of source code at any given time. I consider
that as a biggest breakthrough moving from CVS to SVN.
a
. GIT’s content integrity is better than SVN's:
GIT contents are cryptographically hashed using SHA-1 hash algorithm. This will
ensure the robustness of code contents by making it less prone to repository
corruption due to disk failures, network issues etc. Here is an interesting discussion
2@ Copyright —_by Naresh i TechnologiesNaresh i Technologies By Mr.Nataraj
on GIT’s content integrity — http://stackovertl
ogrity
SUBVERSION GIT
low.com/questions/964331 /git-file-
Understanding Basics
Version Control System
Version Control System (VCS)is a software that helps software developers to work
together and maintain a complete history of their work.
Listed below are the functions of a VCS:
+ Allows developers to work simultaneously.
+ Does not allow overwriting each other's changes,
+ Maintains a history of every version.Naresh i Technologies By Mr.Nataraj
Following are the types of VCS:
+ Centralized version control system (CVCS).
+ Distributed /Decentralized version control system (DVCS).
In this chapter, we will concentrate only on distributed version control system and
especially on Git. Git falls under distributed version control system.
Distributed Version Control System
Centralized version control system (CVCS) uses a central server to store all files and
enables team collaboration, But the major drawback of CVCS is its single point of
failure, ie, failure of the central server. Unfortunately, ifthe central server goes down,
for an hour, then during that hour, ro one can collaborate at all. And even in a worst
«ase, ifthe disk of the central server gets corrupted and proper backup has net been
taken, then you will lose the entire history of the project. Here, distributed version
control system (DVCS) comes into picture.
DVCS clients net only check out the latest snapshot of the directory but they also fully,
mirror the repository. Ifthe sever gces down, then the repository from any client can
be copied back to the server to restore it. Every checkout is a full backup of the
repository, Git does not rely on the central server and that is why you can perform
‘many operations when you are offline. You can commit changes, create branches, view
logs, and perform other operations when you are offline. You require network
connection only to publish your changes and take the latest changes.
1.Advantages of Git
1.1 Free and open source
Git is released under GPL's open source license. It is available freely over the internet.
You can use Git to manage propriety projects without paying a single penny. As itis an
4@ Copyright _by Naresh i TechnologiesNaresh i Technologies By Mr.Nataraj
‘open source, you can download its source code and also perform changes according to
your requirements.
1.2 Fast and small
‘As most of the operations are performed locally, it gives a huge benefit in terms of
speed. Git does not rely on the central server; that is why, there is no need to interact,
with the remote server for every operation performed. The core part of Git is written in
, which avoids -untime overheads associated with other highlevel languages. Though
Git mirrors entire repository, the size of the data on the client side is smell. This
illustrates the efficiency of Git at compressing and storing data on the client side.
1.3 Implicit backup
‘The chances of losing data are very rare when there are multiple copies of it. Data
present on any client side mirrors the repository, hence it can be used in the event of a
crash or disk corruption,
1.4 Security
Git uses a common cryptographic hash function called secure hash function (SHA1), to
name and identify objects within its database. Every file and commit is check-summed
and retrieved by its checksum at the time of checkout: It implies that it is impossible to
change file, date, and commitmessage and any other data from the Git database without
knowing Git.
1.5 Noneed of powerful hardware
In case of CVCS, the central server needs to be powerful enough to serve requests of the
entire team. For smaller teams, it is not an issue, but 2s the team size grows, the
hardware limitations of the server cen be a performance bottleneck. In case of DVCS,
developers don't interact with the server unless they need to push or pull charges. All
the heavy lifting happens on the client side, so the server hardware can be very simple
indeed.
1.6 _ Easier branching
CVCS uses cheap copy mechanism. If we create a new branch, it will copy all the codes
to the new branch, so itis time-consuming and not efficient. Also, deletion and merging
by Narech I'TechaslogiosNaresh i Technologies By Mr.Nataraj
of branches in CVCS is complicated and time-consuming, Eut branch management with
Gitis very simple. It takes only a few seconds to create, delete, and merge branches.
DVCS Terminologies
1.7 Local Repository
Every VCS tool provides a private workplace as a working copy. Developers make
changes in their private workplace and after commit, these changes become a part of
the repository. Git takes it one step further by providing them a private copy of the
whole repository. Users can perform many operations wit this repository such as add
file, remove file, rename file, move file, commit changes, and many more.
18 Working Directory and Staging Area or Index
The working directory is the place where files are checked out. In other CVCS,
developers generally make modifications and commit their changes directly to the
repository. But Git uses a different strategy. Git doesn’t track each and every modified
file. Whenever you do commit an operation, Git looks for the files present inthe staging
area. Only those files present in the staging area are considered for commit and not all
the modified files.
Letus see the basic workflow of Git.
Step 1:You modify a file from the working directory.
Step 2:You add these files to the staging area.
Step 3:You perform commit operation that moves the files from the staging area. After pu
operation, it stores the changes permanently to the Git repository.
6@ Copyright —_by Naresh i Technolo;Naresh i Technologies
Git add operation
Working directory
Staging area
Git commit operation
By Mr.Nataraj
Suppose you modified two files, namely “sort.c" and “search.c’ and you want two
different commits for each operation. You can add one file in the staging area and do
commit. After the first commit, repeat the same procedure for another file.
First commit
|[bash]s git add sorte
# adds file to the staging area
| bash]s git commit -m “Added sort operation”
|# Second commit
tT
'# adds file to the staging area
[bash]s git commit -m “Added search operation’
7© Copyright _by Naresh i Technologies.Naresh i Technologies By MrNataraj
19 Blobs
Blob stands forBinaryLargeObject. Each version ofa file is represented by blob. A blob
holds the file data but doesn’t contain any metadata about the file. It is a binary file and
in Git database, it is named as SHAJ hash of that file. In Git, files are not addressed by
names. Everything is content-addressed,
1.10 Trees
‘Tree is an abject, which represents a directory. It holds blobs as well as other sub-
directories. A tree is a binary file that stores references to blobs and trees which are
also named asSHAAhash of the tree object.
1.11 Commits
Commit holds the current state of the repository. A commit is also named bySHAthash.
You can consider a commit object asa node of the linked list. Every commit object has a
pointer to the parent commit object. From a given commit, you can traverse back by
looking at the parent pointer to view the history of the commit. Ifa commit has multiple
parent commi:s, then that particular commit has been created by merging two
branches.
1.12 Branches
Branches are used to create anothe: line of development. By default, Git has a master
branch, which is same as trunk in Stbversion. Usually, a branch is created to work on a
new feature. Once the feature is completed, it is merged back with the master branch
and we delete the branch. Every branch is referenced ty HEAD, which poin:s to the
latest commit in the branch. Whenever you make a commit, HEAD is updated with the
latest commit.
1.13 Tags
‘Tag assigns a meaningful name with a specific version in the repository. Tags are very
similar to brarches, but the difference is that tags are immutable. It means, tag is a
branch, which robody intends to modify. Once a tag is created for a particular commit,
even if you create a new commit, it will not be updated. Usually, developers create tags
for product releases.
8© Copyright _by Naresh i TechnologiesNaresh i Technologies By Mr.Nataraj
1.14 Clone
Clone operation creates the instance of the repository. Clone operation not only checks
out the working copy, but it also mirrors the complete repository. Users can perform
many operations with this local repository. The only time networking gets involved is.
when the repository instances are being synchronized,
1.15 Pull
Pull operation copies the changes from a remote repository instance to a local one. The
pull operation is used for synchronization between two repository instances. This is
same as the update operation in Subversion.
1.16 Push
Push operation copies changes from a local repository instance to a remote one. This is
used to store the changes permanently into the Git repository. This is same as the
commit operation in Subversion,
1.17 HEAD
HEAD is a pointer, which always poin:s to the latest commit in the branch. Whenever
you make a commit, HEAD is updated withthe latest commis The heads of the branches
are stored ingit/refs /eads /directory
{[Cent0S}$Is-1 git/refs/heads/ master
|[Centos}$ cat git/refs/heads/master
'570837¢7d58fadbecd85cb575d88459218860¢49
118 Revision
Revision represerts the version of the source code. Revisions in Git are represented by
commits. These commits are identified bySHAAsecure hashes.
Contents
1 Git Overview. : = : =
9© Copyright _by Naresh i TechnologiesNaresh i Technologies By Mr.Nataraj
11 Registering.
1.2 Installing Git on Your Machine... se so sn
1.3 Creating a Repository 00 GItRUD «nnn
2 Using Git via Git's Centon inne oe
21 Cloning an Existing RepOSitOFYnovwnmwnnrannennne
22 Creating & Sharing Your Own Projet vcwnennnnnnn
23. Making, Committing & Pushing Change neers
3 Using Git viathe Command Line oven
31. Cloningan Existing Repository... Cn nH
32 Creating & Sharing Your Own Project.
33. Making, Committing & Pushing Changes.
4 Using Git via the Eclipse 25
44 Cloning an Existing Repository...
42 Creating & Sharing Your Own Project.
43. Making, Committing & Pushing Changes.
5 Working With Others.
2 Git Overview
As you develop software and make changes, add features, fix bugs, etc. itis often useful
to have a mechanism to keep track of changes and to ensure that your code base and
artifacts are well-protected by being stored on a reliable server (or multiple servers).
‘This allows you access to historic versions of your application's code in case something
breaks or to “roll-back” to a previous version ifa critical bug is found.
‘The solution is to use a revision control system that allows you to “check-in” changes to
a code base. It keeps track of all changes and allows you to "branch” a code base into a
separate copy so that you can develop features or enhancements in isolation of the
main code base (often called the “trunk” in keeping with the tree metaphor). Once a
branch is completed (and well-tested and reviewed), it can then be merged back into
the main trunk and it becomes part ofthe project.
10@ Copyright _ by Naresh i Technologies.Naresh { Technologies By Mr.Nataraj
You may already be familiar with similar online (or “cloud”) storage systems such as
Google Drive or Dropbox that allow you to share and even collaborate on documents
and other files. However, a version cortrol system is a lot more. It essentially keeps
track of all changes made to a project and allows users to work in large teams on very
complex projects waile minimizing the conficts between changes. These systems are
not only used for organizational and backup purposes, but are absolutely essential
when developing scftware as part of a team. Each team member can have their own
working copy of the project code without interfering with other developer's copies or
the main trunk. Only when separate branches have to be merged into the trunk do
conflicting changes have to be addressed. Otherwise, such a system allows multiple
developers to work on a very complex project in an organized manner.
brane
Figure 1: Trunk, branches, and merging visualization of the Drupal project
‘There are several widely used revision control systems including CVS (Concurrent
Versions System), SVN (Apache Subversion), and Git. CVS is mostly legacy and not as
widely used anymore. SVN is a centralized system: there is a single server that acts as
the main code repository. Individual developers can check out copies and branch
copies (which are also stored in the main repository). They also check all changes into
the main repository.
Git, however, is a decentralized system; multiple servers cen act as repositories, but
each copy on each developer’s own machine is also a complete revision copy. CodeNaresh i Technologies By Mr.Nataraj
commits are committed to the local repository. Merging a branch into another requires
a push/pull request. Decentralizing the system means that anyone's inachine can act as
a code repository and can lead to wider collaboration and independence since different
parties are no longer dependent on onemaster repository.
Git itself is a version control system that can be installed on any server (UNL has a Git
repository setup at https://gitunl.eda). However, we'll primarily focus on Cithub
(https://github.com), the main website used by thousands of developers across the
globe.
‘The rest of this Document will describe how to use Github for use in your courses and
to manage and share your code among your Friends for group assignments and
projects.To work with GITT we need to arrange GIT Server and Client Softwares.
Popular GIT servers used by Industry are:
Assembla:
‘Assembla has a leng history in the business with its Subversion hosting. It includes a
Workspaces platform with issue management, time tracking, and collaboration tools
like wikis and its own messaging system.
Beanstalk:
Being a very lear and reliable service, Beanstalk is a great choice for businesses. It
offers its own deployment infrastruc:ure and integrates well with other tools like
Zendesk, FogBugz, Basecamp, or Lighthouse.
Bitbucket:
Coming from Atlessian, one of the giants in the industry. Therefore, integrations to
other Atlassian products like the JIRA issue tracker are seamless.
CloudForg:
Services go well beyond just code hesting: it calls itself a platform for developers,
offering development tools (eg. Trac or Bugzilla) as well as integrations with j1RA,
Basecamp, and others.
12© Copyright —_by Naresh i TechnologiesNaresh i Technologies By Mr.Nataraj
Codebase:
One of the few platforms that supports Git, Subversion, and Mercurial. Additionally,
ticketing, project management and deployment infrastructure :ools are included,
Fog Creek Kiln:
‘The makers of the popular issue tracking solution "FogBugz” offer a solid code hosting,
platform - and of course. tight integration with their bug tracking system.
GitHub:
‘The undisputed number one in the Open Source world with projects like Java, Ruby on
Rails or jQuery being hosted at GitHub. Offerings include great code review and
collaboration features.
Gitlab:
With an OpenSource background, GitLab offers a fast-evolving platform for code
collaboration. The free community edition and the enterprise edition can be installed
‘on your own servers; a hosted offering that runs on GitLab.com is also available.
Note:Apart from above many more GIT service providers are there in market.
Popular GIT Client Softwares used by Industry are:
Git Clients for Windows
+ Github for windows
+ Sourcetree
+ Aurees
Git Clients for Linux
+ Gite
+ Giggle
+ QgitNaresh i Technologies By Mr.Nataraj
+ GitForce
Git Clients for Mac
2.1 Registering
You can register for a GitHub account at https://github.com/. However, itis strongly
recommended that you get a free “student” account. A normal, free GitHub accoun: does
not allow you to create “private” repositories. Any code you push to GitHub is
automatically public and accessible by anyone. Ths is okay in general, however many
of your courses will have Academic Integrity policies that will require you to notshare
code. student account allows you up to 5 private repositories (normally $7/month as
ofthis writing) so that you can comply with Academic Integrity policies
To get a student account first register at GitHub using an email account that ends in
edu (to “prove" you're a student). Then go to https:/ /education.github.com/pack and
register for a “student pack.” Sign up 2arly as some have reported long wait times to
receive their stucent pack. The studert pack contains a lot of other free and reduced
cost software packages, tools and services that may be of interest.
14@ Copyright —_ by Naresh i TechnologiesNaresh i Technologies By Mr.Nataraj
2.2. Installing Git on Your Machine
If you want to use Git on your own personal machine, then you may need to install a Git
client. There are many options out there and you are ercouraged to explore them,
however the following suggestions are all free and open source.
+ Git has released its own graphical user interface clients which are available for
free for both Windows and Mac:
= Windows: https://windows.github.com/
= Mac: Https://macgithub.com
See section? for instructions onusing the client.
+ If you will be using the Eclipse IDE (http://www.eclipse.org/downloads/) for
development, the most recent versions already come with a Git client. Eclipse will
‘work on any system. See Section 4 for using Git with Eclipse.
+ If you use Windows and prefer to use a command line interface, you can
download and install TortoiseGit (https://code-google.com/p/tortoisegit/) a
Windows Shell Interface to Git. See Section 3 for using Git via the command line
interface,
+ Ifyou use Mac and want the command line version of Git, you can download and.
install here: http://www-git-scm.com/download/mac. Alternatively, you can
install Git using a tool like MacPorts:
http:/ /iamphioxus.org/2013/04/20//installing-git-via-macports-on-mac-osx/. See Section
3 for using Git via the command line interface.
2.3. Creatinga Repository on Github
You will eventually want to publish (‘push") your project code to Github. To do this
you'l first need to create a repository an Github's site:
1. Login to Github (https://github.com/) and click on the “repositories” tab.
2. Create a new repository (see Figure 2) with the name that will match your project
folder (the names do not have te match, but it keeps things organized). Provide a
short description and choose whether or not to make it public or private
depending on whether or not you are allowed to share your code with your peers.
15© Copyright _ by Naresh i TechnologiesNaresh i Technologies By Mr.Nataraj
You may choose to include a README file and/or establish a license (which
creates a LICENSE file). However, for this tutorial we will assume that you start
with an empty repo on Github. If you choose to create these files some extra steps
may be necessary.
eScEtsseaan10
Figure 2: Creating a New Repository on GitHub
3 Using Git via Git’s Clients
In this section we'll explore the basic uses of Git by using Git's client which provides a
Graphical User Interface (GUI) to Git. A complete online help guide is availatle here:
https://macgithub.com/help.htmi(Mac) andere: https:/ windows,
github.com/help.html(Windows):Though the clients should be almost identical for Mac
and Windows, there may be some slight differences;
Popular GIT Client Softwares used by Industry are:
it Clients for Windows
+ Gi vindows
16 Copyright _by Naresh i TechnologiesNaresh i Technologies By Mr.Nataraj
Git Clients for Mac
+ Gitup
+ Fork
Cross-Platform Git Clients
Smartgit
Git Kraken
‘Tower
Git-Cola
GitEye
GitAhead
GIT Lifecycle Diagram
‘lonetpull—p ome ee F
a | re =|
push—t ‘commit — ade.
inde a
Staging Aco onyNaresh i Technologies By MrNataraj
Cloning an Existing Repository
To clone an existing repository hosted on GitHub, point your browser to its URL. On its
page there will be several options to clone, fork or downlcad the repository (see Figure
3
18© Copyright _by Naresh i TechnologiesNaresh i Technologies By Mr.Nataraj
° wee a rese
sree ome ane |
i .
Figure 3: Forking and/or Cloning on GitHub.com
Ifyou click the “Clone in Desktop” option, you'll be prompted to allow the GitHub client
to open and clone the repository to your local file system (you will be prompted to
indicate where unless you've setup a permanent clone path/directory). You will be able
to make changes to your local opy but you will not be able to push changes to the
original project unless you are a collaborator with write permission. However, you can
create a new repository in your GitHub account and push the project back to your own.
repository.
A “fork essentially does this in reverse. Ifyou choose this option, a new repository will
be created in your account and the project will be copied to this new repository. Then,
in your Git client, you can clone it as a local copy to work on by clicking the "Add a
repository” button in the Git client as depicted in Figure 4,Naresh i Technologies By MrNataraj
Figure 4: Cloning in the GitHub Client
3.1 Creating & Sharing Y_ur Own Project
To share/publish a project to GitHub, you can start with an existing project or create a
repository and then start working on your project.
1. Open your Git hub client and click the “Add a repository” button as in Figtre 4.
2, Select the “Create” tab and select the directory of the project you wish to create a
repository with as in Figure 5.
Figure 5: Creating a Repository in the GitHub Client
20© Copyright _by Naresh i Technologies.Naresh / Technologies By Mr.Nataraj
3. Upon success, the Git client should appear as in Figure 6; you can now make an
initial commit by filling in the commit message and descr ption and clicking
“Commit to master”
Figure 6: Committing in the GitHub Client
4. You can now “publish” your repository to GitHub by clicking the “Publish” iccn in
the top right ofthe Git client
5. This opens a new dialog where you can specify the name and descri tion of the
project as it will appear on GitHub.Naresh i Technologies By Mr.Nataraj
Tofinish up, click the “Push Repository” button and observe your new project 01
GitHub
3.2 Making Committing & Pushing Changes
You can make changes to your local project and the changes will automatically be
detected in the Git client. As in the previous step-by-step process, you can select a
subset of changes to commit. Once committed, you can push the changes by clicking the
"Syme" icon at the top right:
waiamieeed
4 Using Git via the Command Line
In this section welll explore the basi: uses of git by using the Command Line Interface
(CLI) utilities. This section assumes tasic familiarity with the unix command line
Advantage: quick, straightforward access to git
Disadvantage: requires good working knowledge of the command line; proficiency
takes longer
22© Copyright _ by Naresh i TechnologiesNaresh i Technologies By Mr.Nataraj
4.1 Cloning an Existing Repository
‘The first thing you may want to do is to “clone” an existing project that has already
been published cn Github. You may do this if your instruccor has provided some code
for assignments or labs.
To start, you can verify that git has been properly installed on your mackine by
‘executing the following: git -version which may output something like:
git version 1.9.5 (Apple Git-50.3)
though your specific version may differ. However, if this command does not work, you
will need to troubleshoot your installation before continuing.
1. Move to the directory where you want the project files to be placed. Usually this
is your “workspace” folder.
2, Execute the following command:
git clone https://github.com/project/url
where the URL is replaced with the URL of the projec: that you want to clone. For
example, ifyou wanted to clone Lab 01 for CSCE 155E/H, which has the url https:
//aithub.ccm/cbourke/CSCE155-C-Lab01, you would execute the commard:
git clone https:/ /github.com/cbourke/CSCE1S5-C-Lab01
3. Ifsuccessful, you should see a message like the following:
Cloning into ‘CSCE155-C-Lab01’... remote: Counting objects:
9, done, remote: Compressing objects: 100% (7/7), done,
remote: Total 9 (delta 2), reused 9 (delta 2), pack-reused 0 Unpacking objects: 100%
(9/9), done.
A new directory/file structure should now exist in your directory and you can
start working with /editing the files,
If the owner of the repository that you just cloned ever makes changes, you can “pull”
those changes from the repository by using git pull to pull all changes.
‘wo Comrie bp Mesech | TechnolcatesNaresh i Technologies By MrNataraj
42 Creating & Sharing Your Own Project
4. Before continuing you will need to create a repository on Github. To do this, refer
to the steps in Section 1.
2. Setup your local repository from the command line by going to your project
directory and executing the fellowing commands (approximate expected outputs
have been included here:
+ Initialize your directory using:
sit init
which should have output similar to:
Initialized empty Git repository in /your/directory/foo/git/
Addall files, directories and subdirectories to your git index using:
git add ~all
+ Commit your files using the following. The -m specifies that a commit
message follows
git commit -m "Initial Commit” Output
should resemble:
[master (root-commit) 723199} Initial Commit
2 files changed, 24 insertions(+) create
mode 100644 READMEmd create mode
1100755 hello.
+ Associate your repo with the repo on GitHub using the following command:
git remote add origin https://github.com/login/PROJECT.git where the
URLis replaced with the URL for your project.
+ Push your commit to the remote repository us ng the following command:
git push -u origin master
Output should resemble something like
Counting objects: 4, dene.
Delta compression usixg up to 8 threads.
24@ Copyright _by Naresh i TechnologiesNaresh i Technologies By Mr.Nataraj
Compressing objects: 190% (4/4), done.
Writing objects: 100% (4/4), 577 bytes | 0 bytes/s, done.
Total 4 (delta 0}, reused 0 (delta 0)
‘Tohttps:/ /github.com/login/PROJECT git
* [new branch] master-> master
Branch master set up to track remote branch master from origin,
3. Refresh ycur browser's Github page to verify the changes were pushed remotely
4.3 Making, Committing & Pushing Changes
Now that your code is committed to Github’s servers, ycu'll eventually want to make
changes to current files and/or add/remove files and commit these changes. Once you
have made your changes, you can essentially repeat part of the process above:
-m "Update Message” git push -u origin mas:er
+ The “Update Message” should be more descriptive: itis used to document the
changes you've made for this commit, It is best practice to be as descriptive as
possible as to your changes.
+ The git add ~all command adds all files in the currert directory as wel as ll ofits
subdirecteries to the commit index. If you want to be more precise and
intentional, you can add individual files using git adc foo.txt, et
5 Using Git via the Eclipse
Eclipse is an industry-standard Integrated Development Environment (IDE) that
integrates code editors (with markup) and build tools to streamline the development
process. There are many plugins anc utilities that can be used with Eclipse to interact,
with git. However, the latest version of Eclipse (Luna as of this writing) supports git
natively. The process below describes how to use this functionality.
Advantage: using a single IDE/interface keeps things simple
Disadvantage: interface can be a bit clunky; it is more difficult to see differences
25@ Copyright —_by Naresh i TechnologiesNaresh i Technologies By MrNataraj
5.1 Cloningan Existing Repository
1. First we need a Git perspective (a context in the Edipse User Interface that will
allow us to work with Git). To open the Git perspective, click on the "Open
Perspective” tab in the upper Fight:
ym Ba,
Select “Gi:" from the menu and click OK
2. Click the ‘Clone a Git repository’ in the Git Repositories navigation menu:
3. Copy/past or type into the URI field, the URL of the project that you want to
clone. For example, if you wanted to clone Lab 01 ‘or CSCE 155E/H, you would
/cbourke/CSCE155-Java-Lab01Then click “Next”
SY RE IPE
4. Once Eclipse has grabbed the project, the “master” branch should be selected
(checkbox); click "Next” again.
26© Copyright _ by Naresh i TechnologiesNaresh i Technologies By Mr.Nataraj
5, Select the directory where you want your project to be saved. Caution: the default
option may not correspond to your default workspace. You may want to change it,
to your workspace, but the choice is yours. Also mark the “Import all existing
projects after done finishes” checkbox option or you will need to manually
import the cloned project into Eclipse.
< eT
C=
6. Switch back to your Java or JavaEE perspective and you can see your cloned
project,
Sica aNaresh i Technologies By Mr.Nataraj
Note: this process assumes that the project you are cloning originated from an Eclipse
project. Eclipse expects that files be organized in a particular way and that
configuration files are present that describe how the project is setup. Ifthe project was
not an Eclipse project, you'll need to clone/setup the projec: in Eclipse manually.
If the owner of the repository that you just cloned ever maxes changes, you can “pull” those
changes from the repository by right-clicking the repo in the Git Perspective and selecting
“Pull”
5.2. Creating & Sharing Your Own Project
Create and develop your own project in Eclipse and get it to the point where you want
to make an initial commit and push to Github. Then do the following:
1. Before continuing you will need :o create a repository on Github. To do this, refer
to the stepsin Section 1.3,
2. Open the Git Perspective in Eclipse.
3, Click the “Create a new re}
tory and add it to this view" icon:
Se ices
4. Select the p-oject folder for the Eclipse project you want to add asa git repo
28@ Copyright —_ by Nareshi TechnologiesNaresh / Technologies By Mr.Nataraj
5. Expand the directory structures and select the file(s) you wish to add to the index
(that is, the files you want to “stage” for your commit), right click and “add to
index’.
oh storm ne
Pe kettecastioet oa
aac
Note: adding a folder (or the entire working directory) to git’s index adds all files
and subfolders within that folder. You can instead, highlight individual files if you
want to be nore precise or intentional with each commit.
6. Right click the rep
ind select “Com
7. Enter a commit message; | it is good for the first commit, but each
‘commit message should be descriptive and document the changes that have been
made. Select the checkboxes of al the files you wish to commit. Click *Commit”
29© Copyright _‘ by Naresh i TechnologiesNaresh I Technologies By Mr.Nataraj
i
ce k
i 5
|
i
===
bak eh I
| mee
Note: you zan see the differences in each file if you double click the file. 8
Right click the repo again and select Remote — Push
9, Enter the URL of the repo you created on http://github.com. Then enter your
Github user name and password.
30© Copyright —_by Naresh i TectnologiesNaresh i Technologies By Mr.Nataraj
Note: this will only work for your repositories or repos on which you are a
collaborator and have been granted write access.
10. Select “master” from the "Source ref" menu and click “Add Spec”. The branch
should now appear in the “Specifications for push” menu. You can now click
“Finish’
310 Copyright _ by Naresh i TechnoloNaresh i Technologies By Mr.Nataraj
11. If successful, a new dialog confirming the push should appear and your files
should be updated on Github,
5.3 Making, Committing & Pushing Changes
Now that your code is committed to Github's servers, you'll eventually want to make
changes to current files and/or ad¢/remove files and commit these changes. Once you
have made your changes, you can essentially repeat part of the process above;
however, steps 1-4 will not be necessary.
‘Note that you don't need to push every commit to Github. You can make as many local
commits as you want. The entire history and all the diffs (differences) are tracked
between each commit.
6 Working With Others
As previously mentioned, you will not be able to pull from a private repo. Nor will you
be able to push to a repo that you do not own or that you are not a collaborator of.
However, you will want to do this when you work wich other individuals either as,
32© Copyright _by Naresh i TechnologiesNaresh i Technologies By Mr.Nataraj
partners for an assignment or as a group in a group project (assuming that your course
instructor's policies allow this of cours2).
‘To do this, simply create a repository that will be used by the group as outlined ay one
of the methods above. You can then grant read/write access to your others by making
them collaborators on the project. You can easily do this in Github by following the
instructions at this link:
https:/ /help github.com/articles/adding-collaborators-to-a-personal-repository/
Once you've all been added, each of you should be able to push/pull from the same
repository.
33@ Copyright —_by Naresh i Technolo:eee ae
eae Remote Repostoryn Gane,
Seether mm Ry os
Cenige TLnaie eps
sa GF ane estas sce
ce re cp
aro Etpenan’ eye ST tr waaay
nh ha Tooning ate
2Gtrepesory err hap Se Ie SEN af eat OWN Ha
‘ioe emote epost
cae eet (1
Spanars bdone G fosry pats econ evan
SzMNeS> Ne etcetera tm ecepeso SA
Mala toceae proj adapt mi
je elem Wega weno
epson Polen) male eee
FRAME Prolect-> Right clck->Team-share projec->GI-) seed ea rposloryfnish
Bight click" project name> team-commit refresh slet all fomunsiaged> oa ther to
$2ge->ta com age epee et ae
Ih econ anette Span bees asa
ai depart vr maaan vr hind cet epson
Sth connote “i
Stopes ee "
Macedo prom palin en pre
Cony nage pe bps 2
Bic yup et poe men opto
Canalo posto aderpe' genta tonsa oj set et
Eee ae i.
soemeam, a ae
Ile dno eg ee wap nd ak seta poten kno plo
eopanrpetieety ne oey wen)
Spy Sees a
lenge ear npotea eoreype,
ae
sige |
‘ae evdoper ete. pt anes remot repay Rt lk noe
‘teain-fetch from upstreaen/pull a
Hetecbeore you commit ore recommended pom th and pl
os
‘opr te now ere Jo ope aa sh
Step T=
Waker develop partormeyFething. Pll open,
Sep
‘Ask evelopert to delet one Jaa fl and conmit push
‘Supt
‘Ask derlope? Tt Fetch and Pl be changes,
‘ep
‘Creating ana Reson comics,
‘)Mate developer! to red line3ot sample tve->commit-Ypah
|) Mate developer? to modi same Une3 without pull cmel-ypudr give ero (rected
son tt forward)
{lake cevloper2>right cick onprojet-> pul change code manly in sampleApp aa
comet > push
Sep teaa
Tove he herol ee rye)
‘ele > ees sow nog
says ca
To conareworpce copy wither epost.
ig ct Locamstertancenole cin tench Syevoned th wae
epi
(eng tanh i
‘exp mast ranch nsale mode ‘
jocatetrweie
ag A cal maser ene beach amemad Ban
itate TL mottygreouces and attng rescues the tanh.
‘see deeper wa opin te brech, i ehekon projet exch choose
smogieeea torent acing ongavee ranch Sih Ghd ov
“iat derelpr toad acatona sn tench.
Otte ToputModt brent BSE |
‘ibe Te marye moat trarchoea/natee i
aes ert nbn ow ok
a =
Fiat sat srg wore, bie cere donee hatch ol eposiong tt —
‘Sows to move bana ranch a mere cur a tach wih anos branch UN
omy hon omnes presence
3 ona aot |
deem tannic oro ona |
‘ikea smetng ona go he ek |
Its entertain ey
sash chances, =
tw pean ie
Sex mp cosines
Gooey ett Ses
Te
‘sng a meray wb done or reese)
reps vew- Tage c-> cal ap manerease 1.0-9chose comet
Imessgeto pln tg meapereted
You might also like
Adv - Java Means Durga Sir... : Durgasoft, Plot No: 202, Iind Floor, Huda Maitrivanam, Ameerpet, Hyderabad-500038
Adv - Java Means Durga Sir... : Durgasoft, Plot No: 202, Iind Floor, Huda Maitrivanam, Ameerpet, Hyderabad-500038
14 pages