GIT and GITHUB
GIT follows the Open source Distributed Version Control System.
Here majority of the work is getting completed on the local repository.
So network usage is less also burden on the server is also less.
DVCS is faster compared to CVCS.
Lets go ahead and do some hands on :
Let us install git on centos.
# yum install git
Once the installation is completed,
# git --version
Let us create a directory gitdemo
and inside gitdemo create a directory project.
# mkdir git-demo
# cd git-demo
# mkdir project
# cd project
# pwd
Now I want git to track the files in the project directory.
Whichever folder you want to tracked by GIT, you need to go into that directory (in this case it is project directory) from thereneed to execute the command git init.
Working directory ---> Staging Area ---> Local Repo
git init (initialize the git to track the files)
ls -al (.git empty repository)
vim index.html (write some code into this file)
ll
git status (it will show the status whether the files are tracked and untracked)
git add index1.html (now this will be in staging area)
git commit -m "adding first file"
git log --oneline (it will show the all the commits)
git show <commit id>
git ls-files (it will list files from the local repo)
vim index2.html
ls
git ls-files
git status
git add index2.html
git commit index2.html -m "adding second file"
git log
git show <commit id>
####modifying the files #########
vim index1.html
git status
git commit -a -m "modified the first file"
git status
vim file.txt
git add file1.txt
git status
git commit -m "new text file"
git status
vim file1.txt
git status
git diff file1.txt (will show u the unstaged changes)
git add file1.txt
git status
git diff --staged file1.txt (it will show the staged changes)
git commit -m "modified text file"
git status
git ls-files
git rm file1.txt (it will delete the file from both working directory and local repo)
git ls-files
ls
git rm --cached index2.html (it will delete the file only from local repo)
ls
git status
git commit -m "deleted the index2.html from local repo but not from the working directory"
ls
git status
git log --oneline
git show <latest commit id>
git ls-files
git status
########### git ignore ######
vim .gitignore (add the filenames to this, those files you dont want to be tracked by git)
git status
git add .gitignore
git commit -m "added the ignore file"
git status
git log --oneline
git add . (to stage all the files)
git commit -m "commiting all the files"
####### modify the commit message ######
git commit --ammend -m "added .gitignore file"
git log --oneline (it will override the commit id and modify the last commit message)
git show <commit id>
##### adding tags to commit #####
git tag --a v2.0 <commit id> -m "added tag" (a is annotation here)
git show v2.0
##### reverting the git commit #####
vim file1.txt
git add file1.txt
git commit -m "added file1.txt"
git log --oneline
git revert <latest commit id> -m "reverted the changes"
git log --oneline
ls (as the commit got reverted file1.txt will be removed from working directory and local repo)
git ls-files
#### reset the commit ####
git reset --hard <commit id>
git status
git log --oneline
#### branch ####
by default we will work on master branch
new requirement with th same code then new branch
git branch (show you all the branches available )
git checkout -b b1 (it will create the new branch b1 and switch to b1 branch)
git log --oneline
git log --oneline master
git branch
vim index3.html
git status
git add index3.html
git commit -m "added first file on b1 branch"
git status
git log --oneline
ls
git checkout (switch to master branch)
git branch
git log --oneline master
ls
#### merge two branches ####
git merge b1
ls
git log --oneline
git log --oneline master
git log --oneline b1
- In Distributed VCS there will be two repositories.
- One is remote server repository and the second is each and every computer is having its own repository.
- Every user will have a local repository and work on this local repository.
- Once the work is done, user will push the repo to the Remote repository.
- If something happens to the remote repo server, no need to worry, every user is having the copy of repository.
- So chances of recovery are more.
Here majority of the work is getting completed on the local repository.
So network usage is less also burden on the server is also less.
DVCS is faster compared to CVCS.
Lets go ahead and do some hands on :
Let us install git on centos.
# yum install git
Once the installation is completed,
# git --version
Let us create a directory gitdemo
and inside gitdemo create a directory project.
# mkdir git-demo
# cd git-demo
# mkdir project
# cd project
# pwd
Now I want git to track the files in the project directory.
Whichever folder you want to tracked by GIT, you need to go into that directory (in this case it is project directory) from thereneed to execute the command git init.
Working directory ---> Staging Area ---> Local Repo
git init (initialize the git to track the files)
ls -al (.git empty repository)
vim index.html (write some code into this file)
ll
git status (it will show the status whether the files are tracked and untracked)
git add index1.html (now this will be in staging area)
git commit -m "adding first file"
git log --oneline (it will show the all the commits)
git show <commit id>
git ls-files (it will list files from the local repo)
vim index2.html
ls
git ls-files
git status
git add index2.html
git commit index2.html -m "adding second file"
git log
git show <commit id>
####modifying the files #########
vim index1.html
git status
git commit -a -m "modified the first file"
git status
vim file.txt
git add file1.txt
git status
git commit -m "new text file"
git status
vim file1.txt
git status
git diff file1.txt (will show u the unstaged changes)
git add file1.txt
git status
git diff --staged file1.txt (it will show the staged changes)
git commit -m "modified text file"
git status
git ls-files
git rm file1.txt (it will delete the file from both working directory and local repo)
git ls-files
ls
git rm --cached index2.html (it will delete the file only from local repo)
ls
git status
git commit -m "deleted the index2.html from local repo but not from the working directory"
ls
git status
git log --oneline
git show <latest commit id>
git ls-files
git status
########### git ignore ######
vim .gitignore (add the filenames to this, those files you dont want to be tracked by git)
git status
git add .gitignore
git commit -m "added the ignore file"
git status
git log --oneline
git add . (to stage all the files)
git commit -m "commiting all the files"
####### modify the commit message ######
git commit --ammend -m "added .gitignore file"
git log --oneline (it will override the commit id and modify the last commit message)
git show <commit id>
##### adding tags to commit #####
git tag --a v2.0 <commit id> -m "added tag" (a is annotation here)
git show v2.0
##### reverting the git commit #####
vim file1.txt
git add file1.txt
git commit -m "added file1.txt"
git log --oneline
git revert <latest commit id> -m "reverted the changes"
git log --oneline
ls (as the commit got reverted file1.txt will be removed from working directory and local repo)
git ls-files
#### reset the commit ####
git reset --hard <commit id>
git status
git log --oneline
#### branch ####
by default we will work on master branch
new requirement with th same code then new branch
git branch (show you all the branches available )
git checkout -b b1 (it will create the new branch b1 and switch to b1 branch)
git log --oneline
git log --oneline master
git branch
vim index3.html
git status
git add index3.html
git commit -m "added first file on b1 branch"
git status
git log --oneline
ls
git checkout (switch to master branch)
git branch
git log --oneline master
ls
#### merge two branches ####
git merge b1
ls
git log --oneline
git log --oneline master
git log --oneline b1
Great Blog!!!!
ReplyDeleteDocker and Kubernetes Training
Docker and Kubernetes Online Training
Docker and Kubernetes Training in Hyderabad
Very Interesting Blog!! Thanks for sharing...
ReplyDeleteDocker Training in Hyderabad
Docker and Kubernetes Online Training