Installing Git is very
easy. Since git is developed Linus who developed Linux OS, git comes by default
with the new versions of Linux.
[root@vx111a
Downloads]# yum install git*
Loaded plugins:
langpacks, product-id, subscription-manager
This system is not
registered to Red Hat Subscription Management. You can use subscription-manager
to register.
Resolving
Dependencies
--> Running
transaction check
---> Package
git.x86_64 0:1.8.3.1-4.el7 will be installed
--> Processing
Dependency: perl-Git = 1.8.3.1-4.el7 for package: git-1.8.3.1-4.el7.x86_64
--> Processing
Dependency: perl(Git) for package: git-1.8.3.1-4.el7.x86_64
--> Running
transaction check
---> Package
perl-Git.noarch 0:1.8.3.1-4.el7 will be installed
--> Finished
Dependency Resolution
Dependencies
Resolved
Once the
installation is done ,we can test the git using,
[root@vx11a] git
–version
Git version 1.8.3.1
If we see the git
version printed, we can confirm the installation is good. We can also use
[root@vx11a] whereis
git : Which gives us the git binary location.
Create a Git Repo
Creating a Git repo
is very easy. Run the “git init” on a new directory after creation. The Git
Repository is then initialized with the below structure.
The .git is a
hidden directory which is actually our local repository. The above snap shot
gives us more details about the contents of the .git directory.
Now once the
repository is created. We need to add files and commit them.
Add a file to the Local Git Repository
Create a java file
as
[root@vx111a
Mytest]# cat hai.java
public class hai {
public static void main(String st[]) {
System.out.println("This Is Git
Sample");
}
}
Now once the file
is created, we need to add them to the git repository by using
Before adding the
file to the git repository ,we can check the status using
[root@vx111a
master]# git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# hai.java
nothing added to commit but untracked files present (use "git add" to track)
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# hai.java
nothing added to commit but untracked files present (use "git add" to track)
We can see that a
new untracked file “Hai.java” exists. Now lets add the file using
[root@vx111a master]# git add . ( or git add <file Name>
The file is now
added to the git repository. Now lets see the status
[root@vx111a master]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: hai.java
#
We can now see that
there is no untracked file. Once the file is added, we then need to make a
commit to the repository so that the changes will be available to the remote
server when we make a push to that. Once the changes are available at the
remote server, other develops can then communicate and get the updated files.
Commit to GIT
Committing files to
git is done by the git commit command like
[root@vx111a
Mytest]# git commit -m "testing GIT"
[master
(root-commit) bad4374] testing GIT
2 files changed, 6 insertions(+)
create mode 100644 Hai.java
create mode 100644 ReadMe
We can see that files,
Hai.java and ReadMe files are both committed to the Git Repository.
More to Come J
No comments :
Post a Comment