Welcome to the world of DevOps! If you're reading this post, chances are you're familiar with Git and GitHub, two of the most popular tools used by developers and teams to manage source code and collaborate on projects. But as a DevOps practitioner, you may find yourself needing to use these tools for more than just version control and code sharing.
That's where this post comes in. We're going to cover some essential Git commands that are useful for DevOps, whether you're deploying applications, managing infrastructure as code, or automating your software development lifecycle.
First, let's briefly review what Git and GitHub are, and how they work together. Git is a distributed version control system that allows you to track changes in your codebase, collaborate with others, and revert to previous versions if necessary. GitHub, on the other hand, is a web-based hosting platform for Git repositories, providing a user-friendly interface for managing your code and collaborating with others.
As a DevOps practitioner, you'll likely be using Git and GitHub in conjunction with other tools and processes, such as continuous integration/continuous deployment (CI/CD) pipelines, infrastructure as code (IaC) tools like Terraform or CloudFormation, and automated testing frameworks. Understanding how to use Git effectively is crucial to ensuring smooth, predictable deployments and minimizing downtime.
In this post, we'll cover a few Git commands that are particularly useful for DevOps:
Here is a list of most essential Git commands that are used daily.
Git Config command : This command is used to create a local repository.
Eg. $ git config --global user.name "ImManeesha"
$ git config --global user.email "kmaneesha525@gmail.com"
Git init command : This command is used to create a local repository.
Syntax
- $ git init Demo
Git clone command : This command is used to make a copy of a repository from an existing URL. If I want a local copy of my repository from GitHub, this command allows creating a local copy of that repository on your local directory from the repository URL.
Syntax
- $ git clone URL
Git add command :This command is used to add one or more files to staging (Index) area.
Syntax
To add one file
- $ git add Filename
To add more than one file
- $ git add*
Git commit command : Commit command is used in two scenarios. They are as follows.
1.Git commit -m
This command changes the head. It records or snapshots the file permanently in the version history with a message.
Syntax
2.git commit -a
This command commits any files added in the repository with git add and also commits any files you've changed since then.
Git status command : he status command is used to display the state of the working directory and the staging area. It allows you to see which changes have been staged, which haven't, and which files aren?t being tracked by Git. It does not show you any information about the committed project history. For this, you need to use the git log. It also lists the files that you've changed and those you still need to add or commit.
Syntax
- $ git status
Git push Command: It is used to upload local repository content to a remote repository. Pushing is an act of transferring commits from your local repository to a remote repo. It's the complement to git fetch, but whereas fetching imports commits to local branches on comparatively pushing exports commits to remote branches. Remote branches are configured by using the git remote command. Pushing is capable of overwriting changes, and caution should be taken when pushing.
Git push command can be used as follows.
Git push origin master
This command sends the changes made on the master branch, to your remote repository.
Syntax
$ git push [variable name] master
Git push -all
This command pushes all the branches to the server repository.
Syntax
$ git push --all
Git pull command :Pull command is used to receive data from GitHub. It fetches and merges changes on the remote server to your working directory.
Syntax
- $ git pull URL
Git Branch Command: This command lists all the branches available in the repository.
Syntax
- $ git branch
Git Merge Command: This command is used to merge the specified branch?s history into the current branch.
Syntax
- $ git merge BranchName
Git log command: This command is used to check the commit history.
Syntax
- $ git log
By default, if no argument passed, Git log shows the most recent commits first. We can limit the number of log entries displayed by passing a number as an option, such as -3 to show only the last three entries.
- $ git log -3
Git remote command: Git Remote command is used to connect your local repository to the remote server. This command allows you to create, view, and delete connections to other repositories. These connections are more like bookmarks rather than direct links into other repositories. This command doesn't provide real-time access to repositories.
So whether you're just starting out with Git and GitHub or are a seasoned veteran, this post will provide you with some useful tips and tricks for managing your code and collaborating effectively with your team. Let's dive in!
/