Quantcast
Channel: Linux World Blog
Viewing all articles
Browse latest Browse all 10

How to Setup and Managed GIT Repository Locally and Remotely

$
0
0

Step 1: Install git rpm

# yum install git

Check it version: # git –version

Step 2:  Set basic  Setting

Set user and email by per account basis, just why i used “—global” as keyword

# git config   –global    user.name   vimal

# git config   –global    user.email   vdaga@lwindia.com

Above command create “~/.gitconfig”  file in your home directory and maintain above record as :

[user]

Name = vimal

Email = vdaga@lwindia.com

You can also list by below cmd

# git config –list

Set system wide setting :

For that we can use “—system” option

# git config  –system  system.name “lw system 1”

# git config –-list

It create “/etc/gitconfig” file, that contain entry for whole system globally, it contain info like

[system]

Name = lw system 1

Note: But if you add same variable in both global and system, it used global one first priority

Set editor for git

# git config  –global  core.editor=vim

Set pager for git

# git config –global core.pager=more

Set which type of file to ignore

# git config –global core.excludesfile  ~/.gitignore_global

And in file ~/.gitignore_global

# Cat ~/.gitignore_global

*~

.DS_Store

Note: “*~”  this is hidden file in linux , not want to upload in git and “.DS_Store”  is hidden file in OS X that not upload in git

 

Step 3 : Create local git repository

# mkdir /myrepo

# cd /myrepo

# git init

# git status

Now start working on “/myrepo” folder, like create your source file, for test is create from

# cp /etc/passwd   /myrepo

Now if you run “status” , it show one untracked file

# git status

To make if trackable, “add” it

# git add passwd  (passwd is file name)

Now if you run “status” , it show one file not commited

To make it commit

# git commit

It show some insertions, that is actually no. of line in files, that would be tracked and commited

# git status

Now its show db is clean

 

To delete file from git repo

# rm passwd

# git status

It say some file delete but not updated into DB

# git rm passwd

# git commit

To ignore particular file to tracked and upload into git repo DB

Create “.gitignore” file in root directory of git repo, for example i want to ignore “shadow” file, so put into this file

# cd  /myrepo

# vim .gitignore

shadow

.gitignore

 

Note: i also ignore “.gitignore” to put into git repo

# cp /etc/shadow  /myrepo

# git status

It will not show any file to tracked with name “shadow”

How to make copy or clone of git repo :

# git clone  /myrepo  /newrepo

# cd /newrepo

# touch file.txt

# git add file.txt

# git commit  –m “this is comment”

# git status

Note : This status say ur branch is ahead of origin branch

So to make update in origin branch, go to origin branch and pull changes

# cd /myrepo

# git pull /newrepo

# ls

You must get the new changes

# cd /newrepo

# git status

It even says not updated

# git push

Do push to update that new changes has been pull by origin source

# git status

How to get remote copy or cloning of repo

Git uses ssh protocol to get remote copy of repo

For eg, your git repo is located at user named vimal at ip address 10.0.0.1, then to get copy of it

# git clone vimal@10.0.0.1:/home/vimal/gitrepo   /localrepo

# cd /localrepo

# git status

 

How to get Tag on git repo

# mkdir /testdir

# cd /testdir

# git init

# cp /etc/passwd   /testdir

# git add passwd

# git commit –m comment1

Check is any tag set

# git tag

To set the tag

# git tag firsttag

# git tag

To show the content in tag

# git show firsttag

To see current tag working

# git describe –tags

Now create one more file on repo

# touch text.txt

# git add text.txt

# git commit  -m comment2

Now see that it automatic set version tag to this file

# git describe –tags

firsttag-1-ergrgg   (in my case)

Now show the content of above tag

# git show firsttag-1-ergrgg

 

How to create annotated tags :

Annotated tag provide and store some extra metadata like comments of the tag

# git tag –a mytag1  -m “comments of tag 1”

# git show mytag1

You can see extra metadata like author , data ,comment of tag

 

How to create branch in git

In single directory to manage many hierarchy of project and department wise project management

To check which branch you are currently in (branch always create after first commit):

# git branch

*master

By default we are always in master branch

To create other branch like “tech”

# git checkout  –b tech

# git branch

master

*tech

It automatic switch to tech branch, * means current branch , you are in

To switch to other branch like master

# git checkout master

Switch to tech

# git checkout tech

If you create something in tech, it only see in tech branch, even if you are in same directory

# touch text.txt

# git add text.txt

# git commit –m comment

# git status

# ls

ls , shows that you have a “text.txt” file in current directory

Now switch to “master” branch

# git checkout master

# ls

Now there is no file named “text.txt” in this branch

To merge “tech” branch in master, then

# git merge tech

 

How to check log of git repo

# git log

Some details log

# git log –p

Top 2 log

# git log –p -2

Show status

# git log –stat

Show in raw format

# git log –p –raw

So summary of log with comments

# git log –pretty=oneline

Show in our own customize format

# git log –pretty=format:‘%h , %an ,%ae , %cn , %cd , %s’

Some basic graph flow format

# git log –pretty=format:‘%h , %an ,%ae , %cn , %cd , %s’  –graph


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images