What is Git? You Must Know

What is Git? Git is a distributed version control system used to track changes in source code during software development. It allows multiple developers to collaborate on projects without interfering with each other’s work.

Repository (Repo):

A repository is a directory or storage space where your project resides, including all of its files and revision history.

Commit:

A commit represents a snapshot of your repository at a specific point in time. It records changes to one or more files in your project.

Branch:

A branch is a parallel version of your repository, allowing you to work on different features or fixes independently. The main branch is typically called. ‘master’.

Merge:

Merging combines changes from different branches into one. This is often done to incorporate the work done in a feature branch back into the main branch.

Pull Request (PR):

A pull request is a request to merge changes from one branch into another. It’s commonly used for code review and collaboration in a team setting.

Basic Commands:

Initialize a Repository:

git init‘: Initializes a new Git repository in the current directory.

Add Files to Staging:

'git add' <file>: Adds a file to the staging area, preparing it for the next commit.

Commit Changes:

git commit -m "Commit message'": Commits the staged changes with a descriptive message.

Check Repository Status:

'git status‘: Shows the current status of the repository, including tracked/untracked files and changes.

View Commit History:

'git log‘ : Displays a chronological list of commits in the repository, including commit messages and authors.

Create a Branch:

'git branch <branch-name>‘: Creates a new branch with the specified name.

Switch Branches:

git checkout <branch-name>‘: Switches to the specified branch.

Merge Branches:

git merge <branch-name>': Merges the changes from the specified branch into the current branch.

Pull Changes from Remote Repository:

'git pull': Fetches changes from the remote repository and merges them into the current branch.

Push Changes to Remote Repository:

git push‘: Uploads local repository content to a remote repository, typically hosted on a platform like GitHub or Bitbucket.

Exit mobile version