Table of contents
- What is Git and why is it important?
- What is difference Between Main Branch and Master Branch?
- Can you explain the difference between Git and GitHub?
- How do you create a new repository on GitHub?
- What is difference between local & remote repository? How to connect local to remote?
- TASKS:
- Set your user name and email address, which will be associated with your commits.
- Create a repository named "Devops" on GitHub:
- Connect your local repository to the repository on GitHub.
- Create a new file in Devops/Git/Day-02.txt & add some content to it:
- Push your local commits to the repository on GitHub:
- Git Branching:
- Git Revert
- Git Reset
- Git Stash:
- Cherry-pick:
What is Git and why is it important?
Git is a version control system that helps developers track changes to their code over time, collaborate with others, and manage multiple versions of a project. It's important because it provides a structured approach to software development, making it easier to manage and collaborate on code.
What is difference Between Main Branch and Master Branch?
In practical terms, the difference between the "main" and "master" branch is largely a matter of convention and preference. Some developers and organizations prefer to use "main" to refer to the default branch, while others continue to use "master".
Regardless of which term is used, the default branch is typically where the latest stable version of the codebase is stored, and other branches are created off of it for experimental features or bug fixes.
Can you explain the difference between Git and GitHub?
Git and GitHub are related but different tools. Git is a version control system that allows developers to track changes to their code over time and collaborate with others on the same codebase. It is a command-line tool that can be used locally on a developer's computer.
On the other hand, GitHub is a web-based hosting service for Git repositories. It provides a platform for developers to store their Git repositories in the cloud, collaborate with others, and share their code with the wider community.
How do you create a new repository on GitHub?
To create a new repository on GitHub, follow these steps:
Log in to your GitHub account.
Click on the "+" icon in the top right corner of the page.
Select "New repository" from the dropdown menu.
Enter a name for your repository.
Add a description if you like (optional).
Choose whether you want the repository to be public or private.
Select the checkbox to "Initialize this repository with a README" (optional).
Choose a license if you like (optional).
Click "Create repository".
What is difference between local & remote repository? How to connect local to remote?
A local repository is a copy of a Git repository that is stored on your own computer, while a remote repository is a copy that is stored on a remote server or hosting service, such as GitHub.
TASKS:
Set your user name and email address, which will be associated with your commits.
git config --global user.name "<name>"
git config --global user.email "<email id>"
To check
git config --list
Create a repository named "Devops" on GitHub:
Connect your local repository to the repository on GitHub.
At first Go to your Repository and copy the URL :
git remote add origin <URL>
Create a new file in Devops/Git/Day-02.txt & add some content to it:
At First Clone this Repo into your local machine:
COPY
git clone <URL>
Create a file in Devops/Git:
git commit -m "<your message"
Push your local commits to the repository on GitHub:
git push -u origin <present branch>You can check it on your Github Account:
you can check it : git branch
You can check it on your Github Account:
Git Branching:
In Git, branches are a part of your everyday development process. Git branches are effectively a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug—no matter how big or how small—you spawn a new branch to encapsulate your changes.
git branch
git branch sub_branch
git checkout sub_branch
Git Revert
Git revert is similar to git reset , but the approach is slightly different. Instead of removing all the commits in its way, the revert ONLY undoes a single commit by taking you back to the staged files before the commit.
git revert <commit i'd>
Git Reset
The git revert command is a forward-moving undo operation that offers a safe method of undoing changes. Instead of deleting or orphaning commits in the commit history, a revert will create a new commit that inverses the changes specified. Git revert is a safer alternative to git reset in regards to losing work.
COPY
git reset
git reset --hard
What Is Git Rebase?
Rebase is one of two Git utilities designed to integrate changes from one branch onto another. Rebasing is the process of combining or moving a sequence of commits on top of a new base commit. Git rebase is the linear process of merging
COPY
git rebase <branch name>
What Is Git Merge?
Merging is Git's way of putting a forked history back together again. The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch. Note that all of the commands presented below merge into the current branch.
git merge <branch name>
Git Stash:
The git stash command takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy. For example: $ git status On branch main Changes to be committed: new file: style
Cherry-pick:
git cherry-pick is a powerful command that enables arbitrary Git commits to be picked by reference and appended to the current working HEAD. Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes.
Git can handle most merges on its own with automatic merging features. A conflict arises when two separate branches have made edits to the same line in a file, or when a file has been deleted in one branch but edited in the other. Conflicts will most likely happen when working in a team environment.
Subscribe to my newsletter
Read articles from Uzair Bagwan's blog directly inside your inbox. Subscribe to the newsletter, and don't miss out.