DevOps – Git and Github Basics
DevOps – Git and Github Basics
Assume, you have important documents and you want to put these documents in a safe place, you can access them very easily as well and you can add more documents in that place as well. In one more scenario, you also want to give access to these documents to someone, just because he/she can analyze these documents and they can do some changes as well.
Moreover, for example, if you earned a degree and want to show this degree worldwide, these features are available in that one place. People learn from you, they can see your achievements and they can take your ideas for reference.
Isn’t it a masterpiece?
The answer is yes.
Now let’s try to understand git technically.
Git Basic Commands
Git is a distributed version control system that allows multiple developers to work on a project simultaneously without overwriting each other’s changes. It tracks changes to files and enables you to revert to previous versions if needed. Here are some core concepts:
Repository (Repo): A Git repository is a directory that contains your project files and the entire history of their changes. This history allows you to track, manage, and revert changes as necessary.
Commit: A commit is a snapshot of your repository at a specific point in time. It’s like taking a picture of your work that you can go back to. Each commit has a unique ID and a message describing the changes made.
Branch: Branching allows you to create a separate line of development within your project. For example, you might have a main branch for production-ready code and a feature branch where you’re developing a new feature. Branches allow you to work on multiple features or fixes simultaneously without affecting the main codebase.
Merge: When your feature or fix is ready, you merge your branch back into the main branch. Merging combines the changes from different branches into a single branch.
Pull Request (PR): In a collaborative environment, a pull request is a way to propose changes to the codebase. It allows others to review and discuss your changes before merging them.
let’s understand some basic git commands.
git init
Purpose: Initializes a new Git repository.
Usage: Run this command in your project directory to start version control.
Example: git init my-new-repo
git clone
Purpose: Copies an existing Git repository from a remote server (like GitHub) to your local machine.
Usage: Use this command to download a repository, including its entire history.
Example: git clone https://github.com/username/repo-name.git
git status
Purpose: Shows the status of your working directory and staging area.
Usage: Use this command to see which files have been modified, added, or are staged for commit.
Example: git status
git add
Purpose: Stages changes for the next commit.
Usage: Use this command to move files from your working directory to the staging area.
Example: git add README.md
git commit
Purpose: Saves your staged changes in the repository with a descriptive message.
Usage: After staging changes, use this command to create a commit.
Example: git commit -m “Added new feature”
git push
Purpose: Uploads your local repository changes to a remote repository.
Usage: Use this command to share your commits with others by pushing them to a remote repository like GitHub.
Example: git push -u origin <branch-name>
git pull
Purpose: Fetches changes from a remote repository and merges them into your current branch.
Usage: Use this command to update your local branch with the latest changes from the remote repository.
Example: git pull origin <branch-name>
git branch
Purpose: Lists, creates, or deletes branches.
Usage: Use this command to manage branches in your repository.
Example: git branch <branch-name>
git checkout
Purpose: Switches between branches or restores files.
Usage: Use this command to switch to a different branch or to check out a specific commit.
Example: git checkout <branch-name>
git merge
Purpose: Merges changes from one branch into another.
Usage: Use this command to combine changes from different branches.
Example: git merge <branch-name>
git log
Purpose: Shows the commit history.
Usage: Use this command to view a list of commits in your repository.
Example: git log
git reset
Purpose: Undoes changes by resetting the current HEAD to a specified state.
Usage: Use this command to unstage changes or revert to a previous commit.
Example: git reset <file-name>
Â
Search
Categories
Latest Posts
DevOps : CI/CD
September 6, 2024DevOps – Virtualization
September 4, 2024DevOps – Git and Github Basics
September 4, 2024Popular Tags