You are on page 1of 17

GIT

Git is an Open Source Distributed Version Control System.Also, Gitprovides features like
branches and merges. Distributed Version Control System: Git has a remote repository which is
stored in a server and a local repository which is stored in the computer of each developer.

Git Workflow:
There are three main components of a Git project:

● Repository
● Working tree
● Index

The repository, or repo, is the “container” that tracks the changes to your project files. It holds
all the commits—a snapshot of all your files at a point in time—that have been made. User can
access the commit history with the Git log.

The working tree, or working directory, consists of files that you are currently working on. You
can think of a working tree as a file system where you can view and modify files.

The index, or staging area, is where commits are prepared. The index compares the files in the
working tree to the files in the repo. When you make a change in the working tree, the index
marks the file as modified before it is committed.
Three states of Git files:
In Git work flow files can be in one of the three states:

● Staged : Staged means that you have marked a modified file in its current version to go
into your next commit.

● Committed: Committed means that the data is safely stored in your local database.

● Modified: The modified files are now safely stored in the repository.

List of tools for version control

1. Gitlab
2. Github
3. BitBucket

Features of the three tools:


For Local self hosted GitLab Community Edition was used.

Setup of Gitlab:

Command for Gitlab setup are as follows:

1. Installing Dependencies:
● sudo apt-get update
● sudo apt-get install ca-certificates curl openssh-server
postfix
You will likely have some of this software installed already. For the postfix
installation, select Internet Site when prompted. On the next screen, enter
your server's domain name or IP address to configure how the system will
send mail.

2. Installing Gitlab:
Download installation script:
● cd /tmp
● curl -LO
https://packages.gitlab.com/install/repositories/gitlab/gitlab
-ce/script.deb.sh

Script can be examined by the below command:


● less /tmp/script.deb.sh
Run the installer
● sudo bash /tmp/script.deb.sh

Install the GitLab Community Edition


● sudo apt-get install gitlab-ce

Edit Gitlab Configuration file


Before using the application, edit one configuration file and run a
reconfiguration command
● sudo nano /etc/gitlab/gitlab.rb
Near the top is the external_url configuration line.Update it to match
your own domain or IP address. If you have a domain, change http to https.

The file will be have the following details as stated below:

/etc/gitlab/gitlab.rb
# If your GitLab server does not have a domain name, you will need to use an IP
# address instead of a domain and keep the protocol as `http`.
external_url 'https://yourdomain' (change the details in this field).

Reconfigure Gitlab File


● sudo gitlab-ctl reconfigure

Initial Configuration Through the Web Interface


Now that GitLab is running and access is permitted, we can perform some initial
configuration of the application through the web interface.

Logging In for the First Time


Visit gitlab domain name in your web browser ( http://gitlab_domain_or_IP) .

On your first time visiting, you should see an initial prompt to set a password for the
administrative account:
In the initial password prompt, supply and confirm a secure password for the administrative
account. Click on the Change your password button when you are finished.

● Username: root
● Password: [the password you set]

Login after password is reset.

Setup For Eclipse:


Go to: Help>Eclipse MarketPlace>EGIT

Install EGit.

Steps to Clone Repository in eclipse:

1. Get the repository details from http://gitlab.orosoftsolutions.com/


2. Go to Your Projects/Projects
3. Click on the repository to get the link to clone project.
4. On the top Clone and copy the HTTP Link.

In Eclipse:

1. Go to File>Import>Git>Project from git


2. Click on Clone URI
3. Enter the URI of the project which needs to be cloned.
4. Enter your username and password
5. Click On next

6. Select the branches which needs to be cloned.


7. Enter the details of an empty directory(mostly your workspace) where projects needs to
be cloned on your local system
8. Select the initial branch which needs to the cloned and click on Next

9. For new Project, Click on the import as general project, click on Next and then Finish.
GitLab Remote Server:

1. Create Project,User.
2. If needed create branch.

SourceTree Setup for Remote Server:

Installation steps:

1. After sourcetree is downloaded,create Atlassian account to use Sourcetree. On the


screen, click either Use an existing account or Go to My Atlassian and follow the
prompts to create a new account. Once you've got an account, you'll be able to log in
with Use an existing account.
2. User can login to the gitlab URL with the credentials and private access token.
3. All the project where user has access will be displayed.

4. User will get the list of project depending on the user permission given by admin.
5. Select the project to clone and enter the local path directory
6. The project will be cloned and user can view both remote server and local project on
sourcetree.

Keywords to remember :

1. Master Repository: place where you upload your Committed files.


2. Local Repository: place on your computer where you save and work on files
3. Commit: store your files to a state/revision on your local repository . These commits serve as
nodes.
4. Branch:A branch in Git is simply a lightweight movable pointer to one of these commits. The
default branchname in Git is master.
5. Head: most recent node on a branch
6. Merge: Combines 2 branch heads together into 1 branch (usually with the Master Branch)
7. Push: Uploads or sends all of your commits to the Master Repository
8. Fetch: Downloads all of the commits from the Master Repository to your Local Repository (DOES
NOT MERGE)
9. Pull: Downloads all of the commits from the Master Repository to your Local Repository AND
MERGES your most recent commit

Now we can pull the existing project or create a new project.

1. Stage/Unstage files,Commit,Push files : Create a new project in the local machine.All the
changes made on the local machine will be visible as uncommitted changes in unstaged
stage.

2. In git bash user can use the command - add.Similar to add in sourcetree user is given the
provision to select the files and click on the stage file.
3. The files which are staged can now be committed with message associated with it.
4. These committed files are available in the git local repository.
5. To push the files on the remote server - click on the push icon.User and select and push the files
on the server.

Pull

User can pull the details from the server for the master(similar to trunk in svn) or any branch.
Step: Click on the pull icon and select the master/branch.

OR
Select the branch or remote>>origin and select pull.

Fetch:
User can click on the fetch icon and select the option to fetch from the following options:
● Fetch from all remotes
● Prune tracking branches no longer present on remote(s).
● Fetch all tags
OR

Left click on Remote>>origin and select fetch from origin.


Branch:
User can either create a new branch or delete any existing branch.

Steps to create a branch.


1. Checkout the already existing branch or master who’s new branch needs to be created.
2. Click on the branch from the menu bar.In the dialog box user will see the following options
● Current checkout branch details
● New branch name -- user needs to enter
● Commit -- user can select from working copy parent or any specified commit
depending on the requirement.
● User can select whether to checkout this branch after creation or continue with the
existing checkout branch.
● Click on create branch.

Command line steps to create new branch

1. git pull
2. Create a new local branch:
git checkout -b branch_name
3. git push origin branch_name
4. git remote add remote_branch_name branch_name
5. git push remote_branch_name remote_url
Delete Branch:

● User can click on the Branch>>Delete Branches.


● All list of remote and local Branch is displayed.
● Select the branch which user wants to delete.
Tag

A tag is used in Git contexts for marking a specific version. Alternatively, tags are used to marks
specific points in the history as important or to mark release points.

Steps to create a Tag:

1. Click on tag in the menu bar.


OR

Select the branch/master local machine or remote and click on the tag option.

2. In the dialog box mention the following details:


● Enter the tag name.
● Commit: select whether user wants to tag a copy of working directory or any
specified commit.
● Select push to orgin if needed.
● Add tag.

Delete Tag: Click on the remove tag and select the tag to be removed.

Merge and Resolve conflict:


1. Checkout the branch/master where user needs to merge.
2. Left click on the branch/master and select merge.
If there is any conflict, go to resolve conflict and do the necessary changes and select
resolved merged.
There is a third party tool diffK3 to resolve conflict if any external tool is needed.
Then stage, commit and push.

You might also like