Commonly used Git commands
As new developers, we often get confused and overwhelmed with all the git commands and how exactly to use them.
Here are explanations and commonly used Git commands for some of the most essential Git operations:
Initialize a Repository:
To start using Git in a project, you need to initialize a Git repository in the project’s root directory. This creates a .git directory to store Git-related information
git initClone a Repository:
To create a local copy of a remote Git repository, you can use git clone. This is often used when you want to start working on an existing project.
git clone <repository_url>Add Changes to Staging Area:
Before committing changes, you need to add them to the staging area. The staging area is where you prepare changes for a commit.
git add <file_name> # Add specific file
git add . # Add all changes in the current directoryCommit Changes:
Committing records changes to the Git repository along with a commit message that describes what changes were made.
git commit -m "Commit message"Check Repository Status:
To see the status of your Git repository, including untracked files, modified files, and files in the staging area.
git statusView Commit History:
Get Priya Salvi’s stories in your inbox
Join Medium for free to get updates from this writer.
You can view the commit history of a Git repository to see who made changes and when.
git logCreate a New Branch:
Branches are used for parallel development. You can create a new branch for a new feature or bug fix.
git checkout -b <branch_name>Switch Branch:
You can switch between branches using git checkout. This allows you to work on different parts of your project.
git checkout <branch_name>Merge Branches:
To combine the changes from one branch into another, you use git merge. It's often used to integrate feature branches into the main branch.
git merge <branch_name>Pull Changes from Remote:
To fetch changes from a remote repository and merge them into your current branch. This keeps your local repository up to date.
git pullPush Changes to Remote:
To push your local commits to a remote repository, use git push. This is necessary to share your changes with others.
git pushResolve Merge Conflicts:
If two branches have conflicting changes, Git will mark them as conflicts. You must manually resolve these conflicts before committing. This is not a single command; you use your text editor or an integrated Git tool to resolve conflicts.
These are some of the fundamental Git commands that you’ll use regularly in your Git workflow. Git has many more commands and options for more advanced scenarios, but mastering these basics will get you started with version control in most software development projects.








