0% found this document useful (0 votes)
114 views

Start A Repository On Git

The document provides instructions for installing Git and setting up a basic Git repository on CentOS Linux. It describes initializing an empty Git repository in a new directory, adding and committing an initial README.MD file, and setting the user name and email configuration values. It then shows pushing the local repository to a new GitHub repository, resolving an authentication error by adding the username to the remote URL.

Uploaded by

mandeep2610
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views

Start A Repository On Git

The document provides instructions for installing Git and setting up a basic Git repository on CentOS Linux. It describes initializing an empty Git repository in a new directory, adding and committing an initial README.MD file, and setting the user name and email configuration values. It then shows pushing the local repository to a new GitHub repository, resolving an authentication error by adding the username to the remote URL.

Uploaded by

mandeep2610
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Start a repository

Start your own local repository, in every folder, is very easy. goto a folder you would like to start
repository inside (like inside your project in /var/www/html) and type at bash:
git init

this will create a .git folder inside your folder which saves all the data for your repository. you can
delete the .git folder now to delete your local repository and return the folder to what it was before the
git init command.
you can use the command:
git status

anytime you want to view your local git status (your need to be inside the project folder, or any
subfolder of it, for this command to work)
Beside the social benefits of git, local repository helps you track versions of your files. compare
them, and restore older version if needed. when git init command creating the .git folder in the first
time, it doesnt track no file. to add files for track you need to use the
git add <filename>

for example you can create an empty (or not) file called README.MD and type:
git add README.MD

you can use wildcard (such as git add *.conf). this way you can add files to the current commit, and
when you ready type:
git commit

you need to provide a commit description. using vim by default (can be changed), and you updated
your repository with you first commit.
You can also add the commit description as a parameter:
git commit -m "My initial commit"

to commit all changes you can use:


git commit -a

to see commits log use:


to commit all changes you can use:
git log

Clone a repository
the following example will cover this topic clearly.
git clone https://github.com/WordPress/WordPress

this line will create a folder wherever you are called WordPress and clone from wordpress repo all
its files. you will a .git folder also, which mean you can continue now with your local repository, and
even update the source if you have the permission to do so.
to update your local version with the server later:
git pull

Clone local repository


You can easily create a clone of your local repo and git pull changes from it:
git clone --no-hardlinks /path/to/repo

Reset Changes from last commit


to reset all the changes you made from the last commit just use:
git reset --hard

Check Difference from last commit


to see the changes made in your git from the last commit use:
git dif

Q for exit.

Use GitHub
Create repository
Create A Repo goto New Repository page in github and create your new repo. this tutorial is for
public & free repo.
you can set a README.MD file to be clone ready immediatly. the following is for a new
repo without README.MD:
after you created a new repository you need to git it to a folder.

New Project
if you want to start your project now, follow inside new directory:
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/<your-user-name>/<project-name>.git
git push -u origin master

Existing Source

if you already have a project your want to create the repo from just go inside your folder, git init it like
above, git add neccesary files (you can use wildcard!) and then resyne the last three line above.

Existing Repo
if you have a local repo which you want to link to your new online repo just use the last two lines of
the bash code above.

* more info: Create A Repo tutorial on github

Push/Pull from/to repository


to push your updates to the server:
git push

to update your local version with the server is the same:


git pull

[root@localhost ~]# yum install git


Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirror.raystedman.net
* extras: mirrors.kernel.org
* updates: mirror.steadfast.net
Resolving Dependencies
--> Running transaction check
---> Package git.i686 0:1.7.1-3.el6_4.1 will be installed
--> Processing Dependency: perl-Git = 1.7.1-3.el6_4.1 for package: git-1.7.1-3.el6_4.1.i686
--> Processing Dependency: perl(Git) for package: git-1.7.1-3.el6_4.1.i686
--> Processing Dependency: perl(Error) for package: git-1.7.1-3.el6_4.1.i686
--> Running transaction check
---> Package perl-Error.noarch 1:0.17015-4.el6 will be installed
---> Package perl-Git.noarch 0:1.7.1-3.el6_4.1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved

================================================================================
Package
Arch
Version
Repository Size
================================================================================
Installing:
git
i686
1.7.1-3.el6_4.1
base
4.5 M
Installing for dependencies:
perl-Error
noarch
1:0.17015-4.el6
base
29 k
perl-Git
noarch
1.7.1-3.el6_4.1
base
28 k
Transaction Summary
================================================================================
Install
3 Package(s)
Total download size: 4.6 M
Installed size: 15 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): git-1.7.1-3.el6_4.1.i686.rpm
| 4.5 MB 00:02
(2/3): perl-Error-0.17015-4.el6.noarch.rpm
| 29 kB 00:00
(3/3): perl-Git-1.7.1-3.el6_4.1.noarch.rpm
| 28 kB 00:00
-------------------------------------------------------------------------------Total
1.3 MB/s | 4.6 MB 00:03
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : 1:perl-Error-0.17015-4.el6.noarch
1/3
Installing : git-1.7.1-3.el6_4.1.i686
2/3
Installing : perl-Git-1.7.1-3.el6_4.1.noarch
3/3
Verifying : 1:perl-Error-0.17015-4.el6.noarch
1/3
Verifying : git-1.7.1-3.el6_4.1.i686
2/3
Verifying : perl-Git-1.7.1-3.el6_4.1.noarch
3/3
Installed:
git.i686 0:1.7.1-3.el6_4.1
Dependency Installed:
perl-Error.noarch 1:0.17015-4.el6

perl-Git.noarch 0:1.7.1-3.el6_4.1

Complete!
[root@localhost ~]# git
usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
[-p|--paginate|--no-pager] [--no-replace-objects]
[--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
[--help] COMMAND [ARGS]
The most commonly used git commands are:
add
Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches

checkout Checkout a branch or paths to the working tree


clone
Clone a repository into a new directory
commit Record changes to the repository
diff
Show changes between commits, commit and working tree, etc
fetch
Download objects and refs from another repository
grep
Print lines matching a pattern
init
Create an empty git repository or reinitialize an existing one
log
Show commit logs
merge
Join two or more development histories together
mv
Move or rename a file, a directory, or a symlink
pull
Fetch from and merge with another repository or a local branch
push
Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset
Reset current HEAD to the specified state
rm
Remove files from the working tree and from the index
show
Show various types of objects
status Show the working tree status
tag
Create, list, delete or verify a tag object signed with GPG
See 'git help COMMAND' for more information on a specific command.
[root@localhost ~]# git config --global user.name "mandeep2610"
[root@localhost ~]# git config --global user.email "[email protected]"
[root@localhost ~]# git config --list
user.name=mandeep2610
[email protected]
[root@localhost ~]# git show
fatal: Not a git repository (or any of the parent directories): .git
[root@localhost ~]# git --show
Unknown option: --show
usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
[-p|--paginate|--no-pager] [--no-replace-objects]
[--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
[--help] COMMAND [ARGS]
[root@localhost ~]# cd Desktop/
[root@localhost Desktop]# cd Chef-Repo
bash: cd: Chef-Repo: No such file or directory
[root@localhost Desktop]# mkdir chef-repo
[root@localhost Desktop]# cd chef-repo/
[root@localhost chef-repo]# git init
Initialized empty Git repository in /root/Desktop/chef-repo/.git/
[root@localhost chef-repo]# git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
[root@localhost chef-repo]# ls
[root@localhost chef-repo]# ls -l
total 0
[root@localhost chef-repo]# touch readme.md
[root@localhost chef-repo]# ls

readme.md
[root@localhost chef-repo]# git add readme.md
[root@localhost chef-repo]# git commit -m "first commit"
[master (root-commit) 1e8ed48] first commit
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 readme.md
[root@localhost chef-repo]# git remote add origin https://github.com/mandeep2610/training.git
[root@localhost chef-repo]# git push -u origin master
error: The requested URL returned error: 403 Forbidden while
accessing https://github.com/mandeep2610/training.git/info/refs
fatal: HTTP request failed

[root@localhost chef-repo]# git remote set-url


origin https://[email protected]/mandeep2610/training.git
[root@localhost chef-repo]# git push -u origin masterCounting objects: 3, done.
Writing objects: 100% (3/3), 209 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://[email protected]/mandeep2610/training.git
* [new branch]
master -> master
Branch master set up to track r

To install Chef on Centos linux


$ curl -L https://www.opscode.com/chef/ install.sh | sudo bash

. In your local shell, run the following command: mma@laptop:~/chef-repo $ curl -L


https://www.opscode.com/chef/ install.sh | sudo bash Downloading Chef...
...TRUNCATED OUTPUT... Thank you for installing Chef!
2. Add the newly installed Ruby to your path:
mma@laptop:~ $ echo 'export PATH="/opt/chef/embedded/bin:$PATH"' >>
~/.bash_profile && source ~/.bash_profile

[root@localhost chef-repo]# yum install curl


Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirror.raystedman.net

* extras: mirrors.kernel.org
* updates: mirror.steadfast.net
Package curl-7.19.7-46.el6.i686 already installed and latest version
Nothing to do
[root@localhost chef-repo]# curl -L https://www.opscode.com/chef/install.sh | sudo bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 18736 100 18736 0 0 21602
0 --:--:-- --:--:-- --:--:-- 166k
Downloading Chef for el...
downloading https://www.opscode.com/chef/metadata?
v=&prerelease=false&nightlies=false&p=el&pv=6&m=i686
to file /tmp/install.sh.3828/metadata.txt
trying wget...
url https://opscode-omnibus-packages.s3.amazonaws.com/el/6/i686/chef-12.4.3-1.el6.i386.rpm
md5 a71d6c0039753ad207848ca385bd0432
sha256 221890739edadcf46501154c8cbdba771612140364ca4afa8290327c4703a1ee
downloaded metadata file looks valid...
downloading https://opscode-omnibus-packages.s3.amazonaws.com/el/6/i686/chef-12.4.3-1.el6.i386.rpm
to file /tmp/install.sh.3828/chef-12.4.3-1.el6.i386.rpm
trying wget...
Comparing checksum with sha256sum...
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
You are installing an omnibus package without a version pin. If you are installing
on production servers via an automated process this is DANGEROUS and you will
be upgraded without warning on new releases, even to new major releases.
Letting the version float is only appropriate in desktop, test, development or
CI/CD environments.
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
Installing Chef
installing with rpm...
warning: /tmp/install.sh.3828/chef-12.4.3-1.el6.i386.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a:
NOKEY
Preparing...
########################################### [100%]
1:chef
########################################### [100%]
Thank you for installing Chef!
[root@localhost chef-repo]# echo 'export PATH="/opt/chef/embedded/bin:$PATH"'>>~/.bash_profile && source
~/.bash_profile
[root@localhost chef-repo]# gem install chef
^[Successfully installed chef-12.4.3
Parsing documentation for chef-12.4.3

^CERROR: Interrupted
[root@localhost chef-repo]# gem
RubyGems is a sophisticated package manager for Ruby. This is a
basic help message containing pointers to more information.

Usage:
gem -h/--help
gem -v/--version
gem command [arguments...] [options...]
Examples:
gem install rake
gem list --local
gem build package.gemspec
gem help install
Further help:
gem help commands
list all 'gem' commands
gem help examples
show some examples of usage
gem help gem_dependencies gem dependencies file guide
gem help platforms
gem platforms guide
gem help <COMMAND>
show help on COMMAND
(e.g. 'gem help install')
gem server
present a web page at
http://localhost:8808/
with info about installed gems
Further information:
http://guides.rubygems.org
[root@localhost chef-repo]#

Regenerate the validation key for your organization and save it as .pem in the .chef
directory inside your chef-repo repository.
4. Generate the Knife config and put the downloaded knife.rb into the .chef
directory inside your chef-repo directory as well. Make sure you replace webops
with the username you chose for Hosted Chef and awo with the short-name you
chose for your organization:
current_dir = File.dirname(__FILE__)
log_level :info
log_location STDOUT
node_name "webops"
client_key "#{current_dir}/webops.pem"
validation_client_name "awo-validator"
validation_key "#{current_dir}/awo-validator.pem"

chef_server_url "https://api.opscode.com/organizations/
awo"
cache_type 'BasicFile'
cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
cookbook_path ["#{current_dir}/../cookbooks"]
5. Use Knife to verify that you can connect to your hosted Chef organization. It should
only have your validator client so far. Instead of awo, you'll see your organization's
short-name:
mma@laptop:~/chef-repo $ knife client list
awo-validator

knife bootstrap 172.16.12.33 --ssh-user vagrant --ssh-password --sudo


vagrant --node-name node1

knife bootstrap 172.16.12.39 --ssh-user vagrant --ssh-password


vagrant --sudo --use-sudo-password --node-name node1
Doing old-style registration with the validation key at
/root/Desktop/chef-repo/devops_me-validator.pem...
Delete your validation key in order to use your user credentials instead
Connecting to 172.16.12.39
172.16.12.39 -----> Installing Chef Omnibus (-v 12)
172.16.12.39 downloading https://www.opscode.com/chef/install.sh
172.16.12.39
to file /tmp/install.sh.1139/install.sh
172.16.12.39 trying wget...
172.16.12.39 Downloading Chef 12 for ubuntu...
172.16.12.39 downloading https://www.opscode.com/chef/metadata?
v=12&prerelease=false&nightlies=false&p=ubuntu&pv=12.04&m=x86_64
172.16.12.39
to file /tmp/install.sh.1143/metadata.txt
172.16.12.39 trying wget...
172.16.12.39 url https://opscode-omnibuspackages.s3.amazonaws.com/ubuntu/12.04/x86_64/chef_12.5.1-1_amd64.deb
172.16.12.39 md5 d8fec2da288e94a7e2d649803a9d70f4
172.16.12.39 sha256
656a4c4a8fd64d74d1d970fb0d07076d6f1d8230d37d751f2c3698a52d82c070
172.16.12.39 downloaded metadata file looks valid...
172.16.12.39 downloading https://opscode-omnibuspackages.s3.amazonaws.com/ubuntu/12.04/x86_64/chef_12.5.1-1_amd64.deb
172.16.12.39
to file /tmp/install.sh.1143/chef_12.5.1-1_amd64.deb
172.16.12.39 trying wget...
172.16.12.39 Comparing checksum with sha256sum...
172.16.12.39 Installing Chef 12

172.16.12.39 installing with dpkg...


172.16.12.39 Selecting previously unselected package chef.
(Reading database ... 51185 files and directories currently installed.)
172.16.12.39 Unpacking chef (from .../chef_12.5.1-1_amd64.deb) ...
172.16.12.39 Setting up chef (12.5.1-1) ...
172.16.12.39 Thank you for installing Chef!
172.16.12.39 Starting the first Chef Client run...
172.16.12.39 Starting Chef Client, version 12.5.1
172.16.12.39 Creating a new client identity for node1 using the validator
key.
172.16.12.39 resolving cookbooks for run list: []
172.16.12.39 Synchronizing Cookbooks:
172.16.12.39 Compiling Cookbooks...
172.16.12.39 [2015-10-29T19:42:10+00:00] WARN: Node node1 has an empty run
list.
172.16.12.39 Converging 0 resources
172.16.12.39
172.16.12.39 Running handlers:
172.16.12.39 Running handlers complete
172.16.12.39 Chef Client finished, 0/0 resources updated in 06 seconds

to remove a package

sudo apt-get --purge remove octave3.2

Set JAVA_HOME / PATH for a single user

Yum install java


Login to your account and open .bash_profile file
$ vi ~/.bash_profile

Set JAVA_HOME as follows using syntax export JAVA_HOME=<path-to-java>. If your


path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:
export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java

Set PATH as follows:


export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

Feel free to replace /usr/java/jdk1.5.0_07 as per your setup. Save and close the file.
Just logout and login back to see new changes. Alternatively, type the following
command to activate the new path settings immediately:
$ source ~/.bash_profile

OR
$ . ~/.bash_profile

Verify new settings:


$ echo $JAVA_HOME

$ echo $PATH

Type Java -version

Download and Install Tomcat


The next task is to install Tomcat on you server and you can install it by downloading it
from the official website of Tomcat. Use the following commands to download Tomcat.
Download the latest version from website as there are many changes in the new version
and its always best to download the latest version to avoid support issues:

wget http://supergsego.com/apache/tomcat/tomcat-7/v7.0.62/bin/apache-tomcat7.0.62.tar.gz

Now extract the package with the tar command:

tar xvf apache-tomcat-7.0.62.tar.gz

mv apache-tomcat-7.0.62 tomcat

Use the following command to start Tomcat on your server and in result you will get the
following results mentioned in the following screenshot:

./bin/startup.sh

Now open your browser and access the URL of Tomcat in your browser where it will
successfully show that you have installed Tomcat on your server and now you are ready
to work on java applications.
To access Tomcat main page, you have to go to your browser and access this link
http://IP_address_of_your_server:8080.

You might also like