GitHub- Source Code Version Control Work Flow- Basics
In this blog I am planning to explore some of the key futures of Git. Git is useful when we are trying to develop code in distributed manner, independent and off the network. GitHub is a web-based repository hosting service, it provide flat from to save your code for open source projects. GitHub provides services through Web GUI, Command Line tool and Desktop tools. In this blog I am focusing on GitHub Desktop futures.
1. Git Background:
- Git is an open source project which is
compatible with most of the operating systems like Mac, Linux, and Windows.
- It’s a distributed version control system, aimed
at speed, data integrity.
- Git is an independent of network and central
server.
- Every git directory on every computer is a full-fledged
repository with complete history and full version-tracking capabilities.
2. GitHub account:
If you don’t have a github account create it using: https://github.com/
Note: The free version of github account creates repository
open for all, if you’re looking for secured/private code management you have to
choose the paid version.
3.
How to install Github on
Desktop:
Download exe file from https://desktop.github.com/
Run the exe file it will take few minutes to check Internet
connectivity.
After github desktop install we should be able to see Git
Shell, GitHub tools in your All programs. In this blog I am planning show how
to use GitHub and manage your code.
Note: Provide your name and email address which we have
created in #2, which enables you make commits on repository.
4. Creating a new git project on Desktop:
4.1. We
can create repository as shown below:
Once the git repository is created we will can see
.gitattributes, .gitignore files. There are three specific reasons to create
these ‘.git*’ files.
a.
If the folder is empty git will be recognize the
folder.
b.
A .gitignore file update with the file types
which git has to ignore during its operations.
c.
A .gitattributes file is a simple text file that
gives attributes to path names.
4.2. We can drag and drop the
complete folder on to github desktop which folder has your project files, it
will create git repository under the same folder:
Note: Git doesn’t make any changes to your folder, it just creates some
hidden files/folder to track your file changes.
4.3. How to add a new file/file updates/remove
files in to your git repository:
If you have new file/file changes in your repository folder
you can provide ‘Summary’ and ‘Description’ to commit your changes to your
local git repository using ‘Changes’ tab. Description is optional.
How to remove/rename a file: Let’s say that Demo_Test_Rename.scala
has been renamed to Demo_Test.scala. GitHub recognize these changes like this:
a. File renamed – GitHub understading file has been
deleted and a new file has been created.
b. File Deleted – GitHub understanding is file has
been deleted.
Note: Without first commit you can’t push your local
repository to host (github.com).
4.4 How
check your commits: Using History you can see your commits, based on your
comments and date & time of commits we can identify your commits.
4.5. SHA-1:
It’s a very important future of git. A
SHA is a hash algorithm checksum to compare added & commit files/file
changes. SHA algorithm generates a 40-hexadecimal string, it’s a unique
identifier to identify each commit on your repository.
Note: In the above GitHub Desktop screen shot SHA contains
only 7 characters. Since we have very less commits and we can identify uniqueness
of commit using less than 10 characters it been shown as 7 character string. If
we can look at the log from GitSheel, we will be able to see the 40 character string
OR we can copy and past it to see 40 character string.
4.6. How
to compare file changes:
Now let’s say that we are making some
changes to “LineCount.scala” and committed it to our local repository. We can
compare it and see what changes has been made from our commit.
4.6.1.
Comparison between your working directory and
git repository:
You can find the difference between your working directory and git
repository easily from ‘Changes’ tab
as shown below:
Here
I just split the comments line in to two lines from one line. GitHub
identifying these changes with ‘–‘ and ‘+’.
4.6.2.
Comparing changes between two commits:
In
our repository we have to commits 41431abf38639dd01a077a5c33b9d046b9bf35fb and 28b7e310a79e036ca296c1de48da4f6aa1b4b8d5
its changes can viewed at:
5. How to create a new GitHub.com repository from
GitHub Desktop:
Click on Publish à
provide your details and Publish & do initial commit.
6. Cloning a new project:
We can close repository in two ways:
6.1. Cloning
a Github.com repository from Github.com:
Open your repository and click on “Set up in
Desktop” and select the folders to create repository.
Now we can see GitHub.com repository on your GitHub desktop:
6.2. Cloning
a Github.com repository from GitHub desktop:
Go to your desktop top right corner and click
on ‘+’ à ‘Clone’
à select the repository
to be cloned. Then select folder when you would like to create local
repository.
Now we can see GitHub.com repository on your GitHub desktop:
7. How to syncing your changes:
Let say that you’re working on A-ZinHadoop
repository using GitHub Desktop. Once your changes are successful you can Push
your changes from GitHub Desktop to https://github.com/repository using Sync
option.
8. Branches: A Branch can be created to
implement your new ideas without creating storage overhead and without
impacting other branches code. At the same time other members can work on
master/new branches to collaborate changes. Once the idea is successful we can
merge it with master branch.
Note: Before creating a branch your current branches
changes should be committed and clean.