DevOps - Lab 2: Basic Commands of Git

Basic Commands of Git

In Lab 2: Basic Commands of Git, participants typically delve into the essential commands that form the core of Git's version control functionality. This lab focuses on hands-on experience with commands such as 'git add' to stage changes, 'git commit' to save changes to the repository, and 'git status' to view the status of the working directory. Participants may also explore 'git log' to review commit history and 'git branch' for managing branches. This foundational lab aims to deepen participants' understanding of basic Git operations, empowering them to navigate version control efficiently. Mastery of these fundamental commands is crucial for effective collaboration and version management in software development projects using Git. Successful completion of Lab 2 equips participants with the skills needed to initiate, track changes, and maintain a structured version history in their Git repositories.

Lab:

1 .gitingnore

Step 1: Create .gitignore file and give pattern matching (e.g. *.class, *.jar)

vi .gitignore
(Press i)
\*.class
\*.jar
(Press esc)
:wq!

Step 2: Add & Commit .gitignore file

git add .gitignore
git commit -m ".gitignore"

Step 3: Add some files for testing

touch 1.txt 2.txt 3.txt
touch 4.class 5.class 6.class
touch 7.jar 8.jar 9.jar
ls
git add .
git status
  1. Resetting changes (Before Commit)

To reset from staging area

git reset <filename>
git reset .

To hard reset from staging area

git reset --hard
  1. Reverting changes (After Commit)

To revert the changes

git revert <commit-id> 

Revert will create a new commit-id (all changes will be tracked) 
You need not to add and commit again. Automatically new commit-id will be generated
  1. Removing files

To remove files

git rm <file name>


      Then commit (no need to add)
      Gets deleted from that particular branch
  1. Deleting all untracked files

To delete all untracked files

git clean -n (dry run)
git clean -f
  1. TAGs

To apply tag

git tag –a <tag name> -m <tag message> <commit-id> 

To see the list of tags

git tag

To see particular commit content by using tag

git show <tag name>

To delete a tag

git tag –d <tag name>