Git Guide
Git Guide
Git Guide
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.
1. Gitlab
2. Github
3. BitBucket
Setup of Gitlab:
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
/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).
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]
Install EGit.
In Eclipse:
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.
Installation steps:
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. 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
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:
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.
Select the branch/master local machine or remote and click on the tag option.
Delete Tag: Click on the remove tag and select the tag to be removed.