Blog Post

Azure Infrastructure Blog
3 MIN READ

Commonly Used Git Commands

Parvathy_R_Pillai's avatar
Apr 15, 2025

Git is a distributed version control system that allows developers to track changes in their codebase, collaborate with others, and manage project versions efficiently. This whitepaper provides a comprehensive list of commonly used Git commands, along with explanations and examples to help you get started with Git.

Configuring Git

Before using Git, you need to configure your user information, such as your name and email address. This information will be associated with your commits.

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Creating a Repository

Git init is used to initialize a new Git repository. It creates a new. git directory in your current directory.

git init

Cloning a Repository

To create a working copy of a local repository, use:

git clone /path/to/repository

For a remote server, use:

git clone username@host:/path/to/repository

Adding Files

To add one or more files to the staging area (index), use:

git add <filename>
git add *

Git add is used to add files to the staging area, preparing them for a commit.

Committing Changes

To commit changes to the head (but not yet to the remote repository), use:

git commit -m "Commit message"

To commit any files, you've added with git add, and also commit any files you've changed since then, use:

git commit -a

Pushing Changes

To send changes to the master branch of your remote repository, use:

git push origin master

Checking Status

To list the files, you've changed and those you still need to add or commit, use:

git status 

Git status shows the status of changed files in the working directory and staging area.

Connecting to a Remote Repository

If you haven't connected your local repository to a remote server, add the server to be able to push to it:

git remote add origin <server>

To list all currently configured remote repositories, use:

git remote -v

Working with Branches

To create a new branch and switch to it, use:

git checkout -b <branchname>

To switch from one branch to another, use:

git checkout <branchname>

To list all the branches in your repo and also tell you what branch you're currently in, use:

git branch

To delete a feature branch, use:

git branch -d <branchname>

To push the branch to your remote repository so others can use it, use:

git push origin <branchname>

To push all branches to your remote repository, use:

git push --all origin

To delete a branch on your remote repository, use:

git push origin :<branchname>

Git fetch

Git Fetch is used to download updates from a remote repository, but it does not merge those changes or alter your current working code.

Git stash

Git stash is used to save changes that you want to keep but not commit immediately.

git stash 

Git Log

Git log command displays an extensive list of all the commits that have been made to the current repository. The commits are displayed in reverse chronological order (most recent commits first) and provide details like the author of the commit, the date the changes were committed, and a brief summary of the changes.

Git revert

Git revert is used to create a new commit that undoes the changes made in a previous commit.

Updating from the Remote Repository

git pull

Git pull is used to fetch changes from a remote repository and merge them into the current branch.

Conclusion:

This whitepaper covers the essential Git commands that are commonly used in day-to-day development. By mastering these commands, you can efficiently manage your codebase, collaborate with your team, and maintain a clean project history.

For more detailed information and advanced Git commands, refer to the official Git documentation.

Updated Nov 09, 2024
Version 1.0
No CommentsBe the first to comment