100 Days of DevOps — Day 74- Introduction to GIT

# yum -y install git
# git --versiongit version 1.8.3.1
# git config --global user.name “plakhera”# git config --global user.nameplakhera
# git config --global user.email “test@gmail.com”# git config --global user.emailtest@gmail.com
# cat ~/.gitconfig[user]name = plakheraemail = test@gmail.com
# git config --listuser.name=plakherauser.email=test@gmail.com
# git config --global color.ui true
# git config --global core.autocrlf input
# It will run status command in silent mode
#
git config — global alias.s “status -s”
# To show log in oneline, with all branches,along with graph and decorate the output of content
#
git config — global alias.l “log --oneline --all --graph --decorate”
# git init myfirstprojectInitialized empty Git repository in /root/myfirstproject/.git/
# cd myfirstproject/# git status# On branch master## Initial commit#nothing to commit (create/copy files and use “git add” to track)
# touch firstfile# git status# On branch master## Initial commit## Untracked files:# (use “git add <file>…” to include in what will be committed)## firstfilenothing added to commit but untracked files present (use “git add” to track)
# git commit -m “my first project file”[master (root-commit) 8e3d2a5] my first project file1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 firstfile
  • master: it’s telling us that it’s the master branch
  • root-commit: it’s the first commit we create this project
  • 8e3d2a5: sha hash and that is the unique identifier for the commit
  • 1 file changed: which is self explanatory as we only made changes to one file
  • 100644: which is a standard unix permission set
# git status# On branch masternothing to commit, working directory clean
# git logcommit 8e3d2a58e5c9182f2d646d1b0586a58ba1d5c17bAuthor: plakhera <laprashant@gmail.com>Date: Thu Apr 20 12:02:41 2017 -0400my first project file
  • Commit hash
  • Author of the commit
  • Date when we commit these changes
  • Commit message
# git l* 8e3d2a5 (HEAD, master) my first project file
  • GIT way
# git mv firstfile secondfile# It staged the file too
#
git status
# On branch master# Changes to be committed:# (use “git reset HEAD <file>…” to unstage)## renamed: firstfile -> secondfile# git commit -m "rename firstfile to secondfile"[master de2c659] rename firstfile to secondfile1 file changed, 0 insertions(+), 0 deletions(-)rename firstfile => secondfile (100%)
  • Unix way
# mv secondfile thirdfile# git status# On branch master# Changes not staged for commit:# (use “git add/rm <file>…” to update what will be committed)# (use “git checkout — <file>…” to discard changes in working directory)## deleted: secondfile## Untracked files:# (use “git add <file>…” to include in what will be committed)## thirdfileno changes added to commit (use “git add” and/or “git commit -a”)# git add -A .# git commit -m “renaming secondfile to thirdfile”[master 5ada133] renaming secondfile to thirdfile1 file changed, 0 insertions(+), 0 deletions(-)rename secondfile => thirdfile (100%)
# git add .warning: You ran ‘git add’ with neither ‘-A ( — all)’ or ‘ — ignore-removal’,whose behaviour will change in Git 2.0 with respect to paths you removed.Paths like ‘secondfile’ that areremoved from your working tree are ignored with this version of Git.* ‘git add — ignore-removal <pathspec>’, which is the current default,ignores paths you removed from your working tree.* ‘git add — all <pathspec>’ will let you also record the removals.Run ‘git status’ to check the paths you removed from your working tree.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prashant Lakhera

Prashant Lakhera

4.91K Followers

AWS Community Builder, Ex-Redhat, Author, Blogger, YouTuber, RHCA, RHCDS, RHCE, Docker Certified,4XAWS, CCNA, MCP, Certified Jenkins, Terraform Certified, 1XGCP