Git command you need to know
Table of contents
No headings in the article.
Version control is an essential tool for any software development team, and Git is one of the most popular version control systems used today. Git is a distributed version control system, meaning that it allows multiple people to work on the same codebase at the same time, without interfering with each other's work. In this blog, we'll cover some of the fundamental concepts of Git, including status, add, commit, clone, origin, branches, remote, upstream, merge, and conflict.
Status: The status command is used to display the current state of your Git repository. It shows which files have been modified, which files are staged and ready to be committed, and which files are untracked. You can run the command "git status" to see the current state of your repository.
Example command: git status
Add: The add command is used to stage changes to be committed. When you make changes to a file in your repository, those changes are not automatically committed. Instead, you need to add those changes to the staging area using the "git add" command. Once you've added your changes, you can commit them using the "git commit" command.
Example command: git add file.txt
Commit: The commit command is used to save changes to the repository. When you commit changes, you're creating a new version of the codebase that you can reference later. Each commit has a unique identifier that allows you to track changes over time. You can run the command "git commit" to commit your changes.
Example command: git commit -m "Added new feature"
Clone: The clone command is used to create a local copy of a remote repository. When you clone a repository, you're creating a complete copy of the repository on your local machine. You can then work on the codebase locally and push changes back to the remote repository when you're ready. You can run the command "git clone" followed by the URL of the remote repository to clone it.
Example command: git clone
https://github.com/username/repo.git
Origin: The origin is the default name for the remote repository that you cloned from. When you clone a repository, Git automatically sets up a remote called "origin" that points to the original repository. You can use this remote to pull changes from the remote repository or push changes back to it.
Example command: git remote add origin
https://github.com/username/repo.git
Branches: Branches are used to create separate lines of development within a Git repository. When you create a new branch, you're creating a copy of the current codebase that you can work on independently. You can use branches to work on new features, bug fixes, or experiments without affecting the main codebase. You can create a new branch using the "git branch" command.
Example command: git branch new-feature
Remote: A remote is a reference to a remote repository that you can interact with using Git. When you clone a repository, Git automatically sets up a remote called "origin" that points to the original repository. You can also set up additional remotes to interact with other repositories. You can use remotes to pull changes from a remote repository or push changes back to it.
Example command: git remote add upstream
https://github.com/otheruser/repo.git
Upstream: Upstream is a reference to the original repository that you cloned from. When you clone a repository, Git sets up a remote called "origin" that points to the original repository. The original repository is known as the upstream repository. You can use the upstream repository to pull changes from the original repository into your local repository.
Example command: git fetch upstream
Merge: The merge command is used to combine changes from one branch into another. When you merge a branch, you're taking the changes that were made on that branch and applying them to another branch. This allows you to bring changes from separate branches together into a single codebase. You can run the command "git merge" followed by the name of the branch that you want to merge.
Example command: git merge feature-branch
Conflict: A conflict occurs when Git is unable to automatically merge changes from two branches. When this happens, Git will pause the merge and prompt you to resolve the conflict manually. Conflicts can occur when two people make changes to the same file at the same time, or when changes made on one branch conflict with changes made on another branch. You can resolve conflicts by editing the files that have conflicts and then committing the changes.
Example command: git merge feature-branch
(if a conflict occurs, Git will prompt you to resolve it manually)
Git is a powerful version control system that enables teams to work together on codebases efficiently. Understanding the basic concepts of Git, including status, add, commit, clone, origin, branches, remote, upstream, merge, and conflict, is crucial for anyone working with Git. By using Git effectively, you can keep track of changes to your codebase, work on features independently, and collaborate with others effectively.