What is Git? — Git operation and command
Git is a distributed version control system that allows you to keep track of changes made to files and collaborate with others on a project.
Git’s goal is to manage a project or set of files as they change over time. Git stores this data in a data structure known as a Git repository. Git’s heart is the repository. To be clear, a Git repository is the directory that contains all of your project files and metadata. Git keeps track of the project’s current state by creating a tree graph from the index. It is typically represented by a Directed Acyclic Graph (DAG).
Here are some common Git commands and their operations:
1. git init — Initializes a Git repository in the current directory.
syntax: git init [repository name]
This command is used to start a new repository.
2. git clone — Clones a Git repository from a remote source to your local machine.
syntax: git clone [url]
This command is used to obtain a repository from an existing URL.
3. git add — Adds changes in the working directory to the staging area.
syntax: git add [file]
This command adds one or more files to the staging area.
syntax: git add .
This command adds one or more to the staging area.
4. git commit — Records changes to the repository by creating a new commit that includes the changes in the staging area.
syntax: git commit -m [ Type in the commit message]
This command records or snapshots the file permanently in the version history.
5. git status — Displays the current status of the repository, including which files have been modified and added to the staging area.
syntax: git status
This command lists all the files that have to be committed.
6. git log — Shows a list of all commits in the current branch, along with their details such as the author, date, and message.
syntax: git log
This command is used to list the version history for the current branch.
7. git branch — Allows you to create, list, and delete branches in a Git repository.
syntax: git branch
This command lists all the local branches in the current repository.
syntax: git branch [branch name]
This command creates a new branch.
syntax: git branch -d [branch name]
This command deletes the feature branch.
8. git checkout — Switches between branches or restores files in the working directory to a specific commit.
syntax: git checkout [branch name]
This command is used to switch from one branch to another.
syntax: git checkout -b [branch name]
This command creates a new branch and also switches to it.
9. git merge — Merges changes from one branch into another, resolving any conflicts that may arise.
syntax: git merge [branch name]
This command merges the specified branch’s history into the current branch.
10. git push — Pushes changes from the local repository to a remote repository, such as GitHub.
syntax: git push [variable name] main
This command sends the committed changes of main branch to your remote repository.
syntax: git push [variable name] :[branch name]
This command sends the branch commits to your remote repository.
syntax: git push -all [variable name]
This command pushes all branches to your remote repository.
11. git pull — Pulls changes from a remote repository to the local repository.
syntax: git pull [Repository Link]
This command fetches and merges changes on the remote server to your working directory.
12. git diff — Shows the differences between two commits, the working directory and the staging area, or the staging area and the repository.
syntax: git diff
This command shows the file differences which are not yet staged.
syntax: git diff –staged
This command shows the differences between the files in the staging area and the latest version present.
syntax: git diff [first branch] [second branch]
This command shows the differences between the two branches mentioned.
Mastering DevOps: A Comprehensive Step-by-Step Guide to Elevate Your Skills and Enhance Your Workflow
1. Software Development Life Cycle (SDLC)
5. What is Git? — Git operation and command
6. What is Version Control System? — Git vs GitHub
7. The Most Important Linux Commands
8. Vagrant — The Complete Guide
9. The Power of Virtualization
10. Networking Guide
11. Bash Scripts: An In-Depth Tutorial
12. Architecture: Monolithic vs Microservices
13. CI/CD Workflow with Jenkins
14. Automating Your Infrastructure with Ansible
15. Docker Made Easy From Beginner to Advanced in One Guide
16. Creating a Custom Docker Image
17. Examples of Docker File With Various Application Stacks
18. Kubernetes A Beginner’s Tutorial
19. Kubernetes feature: Pods, Services, Replicasets, Controllers, Namespaces, Config, and Secrets
20. Terraform: Simplify Infrastructure Management
Level up your DevOps skills with our easy-to-follow tutorials, perfect for acing exams and expanding your knowledge. Stay tuned for more concepts and hands-on projects to boost your expertise!