Monday, 8 September 2025

Core Git Commands for DevOps in Production

 

1. Cloning Repositories


rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj
$ git clone https://github.com/rajkumargupta14/hello-world-1.git
Cloning into 'hello-world-1'...
remote: Enumerating objects: 345, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 345 (delta 3), reused 2 (delta 2), pack-reused 339 (from 2)
Receiving objects: 100% (345/345), 48.93 KiB | 1.40 MiB/s, done.
Resolving deltas: 100% (78/78), done.

2.  Do the required changes in code like in below case done changes in index.jsp file

rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main (master)
$ cd webapp/

rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ ls
WEB-INF/  index.jsp
rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ vi index.jsp


3.  Check the git status

rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   index.jsp

no changes added to commit (use "git add" and/or "git commit -a")

4.  Add all changes to local repo

rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ git add .

rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   index.jsp



5. Saves changes to the local repository with a message.:-


rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ git commit -m "Updated the index file"
[master b81dd6a] Updated the index file
 Committer: Gupta <raj.f.gupta@capgemini.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+), 1 deletion(-)

rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean


6. Commit to remote repo it will open browser to  validate with your GitHub account after verification it will merge the code:-


rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ git push origin master
info: please complete authentication in your browser...
Enumerating objects: 13, done.
Counting objects: 100% (13/13), done.
Delta compression using up to 12 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (7/7), 548 bytes | 78.00 KiB/s, done.
Total 7 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/rajkumargupta14/hello-world-1.git
   53817e9..b81dd6a  master -> master

rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$






No comments:

Post a Comment