Git Commands to increase your Productivity

Git Commands to increase your Productivity
Git Commands to increase your Productivity

Git is a distributed version control system that helps developers collaborate on projects of any scale.

Linux kernel developer Linus Torvalds created Git in 2005 to help control development of the Linux kernel.

What is a Distributed Version Control System?

Git makes collaboration easy. Everyone on the team can keep a full backup of the repositories they’re working on on their local machine. Then, thanks to an external server like BitBucket, GitHub or GitLab, they can safely store the repository in one place.

This way, different team members can copy it locally and everyone gets a clear overview of all the changes made by the entire team.

Read Also – What is SonarQube? Explain in detail.

How to check your Git configuration:

git config -l

The command above returns a list of information about your git configuration including user name and email

How to setup your Git username:

git config --global user.name "Fabio"

With the command above you can configure your user name:

How to setup your Git user email:

This command lets you setup the user email address you’ll use in your commits.

git config --global user.email "signups@fabiopacifici.com"

How to cache your login credentials in Git:

You can store login credentials in the cache so you don’t have to type them in each time. Just use this command:

git config --global credential.helper cache

How to initialize a Git repo:

Everything starts from here. The first step is to initialize a new Git repo locally in your project root. You can do so with the command :

git init

How to add a file to the staging area in Git:

The command below will add a file to the staging area. Just replace filename_here with the name of the file you want to add to the staging area.

git add filename_here

How to add all files in the staging area in Git:

If you want to add all files in your project to the staging area, you can use a wildcard . and every file will be added for you.

git add .

How to add only certain files to the staging area in Git

With the asterisk in the command below, you can add all files starting with ‘fil’ in the staging area.

git add fil*

How to check a repository’s status in Git:

This command will show the status of the current repository including staged, unstaged, and untracked files.

git status

How to commit changes in the editor in Git:

This command will open a text editor in the terminal where you can write a full commit message.

A commit message is made up of a short summary of changes, an empty line, and a full description of the changes after it.

git commit

How to commit changes with a message in Git:

You can add a commit message without opening the editor. This command lets you only specify a short summary for your commit message.

git commit -m "your commit message here"

How to commit changes (and skip the staging area) in Git:

You can add and commit tracked files with a single command by using the -a and -m options.

git commit -a -m"your commit message here"

How to see your commit history in Git:

This command shows the commit history for the current repository:

git log

How to see your commit history including changes in Git:

This command shows the commit’s history including all files and their changes:

git log -p

How to see a specific commit in Git:

This command shows a specific commit.

Replace commit-id with the id of the commit that you find in the commit log after the word commit

git show commit-id

How to check remote branches that Git is tracking:

This command shows the name of all remote branches that Git is tracking for the current repository:

git branch -r

How to fetch remote repo changes in Git:

This command will download the changes from a remote repo but will not perform a merge on your local branch 

git fetch

How to merge a remote repo with your local repo in Git:

If the remote repository has changes you want to merge with your local, then this command will do that for you:

git merge origin/main

How to get the contents of remote branches in Git without automatically merging:

This lets you update the remote without merging any content into the
local branches. You can call git merge or git checkout to do the merge.

git remote update

How to push a new branch to a remote repo in Git:

If you want to push a branch to a remote repository you can use the command below. Just remember to add -u to create the branch upstream:

git push -u origin branch_name

How to remove a remote branch in Git:

If you no longer need a remote branch you can remove it using the command below:

git push --delete origin branch_name_here

How to use Git rebase:

You can transfer completed work from one branch to another using git rebase.

git rebase branch_name_here

How to force a push request in Git:

This command will force a push request. This is usually fine for pull request branches because nobody else should have cloned them.
But this isn’t something that you want to do with public repos.

git push -f

Tag –

Git Commands to increase your Productivity

Mahesh Wabale
Latest posts by Mahesh Wabale (see all)

Leave a Comment