Practicals On GITA
Practicals On GITA
Git is a free and open source distributed version control system designed to handle everything
from small to very large projects with speed and efficiency. Git is easy to learn and has a tiny
footprint with lightning fast performance. It outclasses SCM tools like Subversion, CVS,
Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and
multiple workflows.
Some of the basic operations in Git are:
1. Initialize
2. Add
3. Commit
4. Pull
5. Push
1. Branching
2. Merging
3. Rebasing
Once installation is done, open the terminal in Ubuntu and perform the following steps or in
windows Right click and select Git bash here.
The output of GIT Bash in windows and GIT shell in Ubuntu is shown below
The output of above command shown below which adds .git hidden directory in current
repository.
$ rm -rf .git/
$ git init
Initialized empty Git repository in C:/Users/ADMIN/Desktop/git-dvcs/git-demo-
project/.git/
To add files in the repository by create or copy some doc,html,image files inside
current directory to see index and staging area. The add command is used along with
dot (. Dot means current directory) for adding files in current repository i.e. making
them in staging mode. They are untracked until we commit them.
$ git add .
Index and staging area
To check the status of repository, use
$ git status
Which will show you some untrack files, so untracks files can be tracked using commit
command.
$ touch teststatus
Now let us see history of commits. The log command is used for seeing the commit history.
$ git log
Example 2: Performing Version control in GITHUB with Pull and Push commands
First open Github.com and create a new account.After verifying account through E-mail, create a
Repository on github.com.
Open github.com→ create an account→After login Select New repository from the menu.
Login with another account→Copy and Paste URL of repository→then just click on fork to
clone to others account. Suppose we want to fork public repository “timetracker”. So search for
“timetracker” github repository on google and once its opened clicked on “Fork button” from the
top of the github web page as shown below.
Now, if you want to download a repository in local machine, then git clone command is used
followed by path to repository. In GitHub the path of repository can be known through clone or
download button and it can be downloaded using git clone command as shown below.
The pull command used to fetch the repository from github to local while push is used to commit files
from local repository to Github.
The following commands are used for pull and push repositories
A) Push command
B) Pull Changes
$ git pull
Now you can see the changes in local repository using git log.
C) Fetch
Suppose you have a file in github and you have changes that.
ORIGINAL FILE
Changed File
Here fetch will not show you like updated changes file as like push. So use merge
command to merge the changes so use following command for merge.
$ git merge origin/master