My Day To Day Git Commands

Git Commands And Their Uses.

Adejoke Ogundipe
5 min readJan 29, 2023
img: google.com

Today I will be blessing us with some of the standard git commands I use daily at work. Hello to my upcoming and senior developers, I appreciate what you guys do every day. Well done and keep up the good work.

img: google.com

Git commands

git branch — show-current

Kindly note: it is with two dashes.

The above git command, like the name implies, shows the current branch name you are on. The response will be the name of the current branch you are on like either “develop” or sub-branch name as the case may be.

img: — show-current branch

git init

Before starting anything on a new directory we use git init, it helps to change a directory to an empty git repository locally.

git pull

This is used to pull all the new changes into the current branch.

git reset — hard origin/develop

This is a command to set the local branch against the origin, just like how rebasing works.

git reflog

img: google.com

This command is a lifesaver. I had to check out to another branch to complete a quick update, and when I checked back to the original branch I was working on initially, I could not see what I had been working on. A colleague of mine introduced me to git reflog, which prevented me from having to start over by writing the code.

git pull origin develop

We are familiar with git pull origin development, this is the git command to pull the changes from the remote origin to our local branch. In my case, my origin branch is named develop so most times I pull to my local in order to update my local branch. We can also use just git pull.

git rebase — develop

This is simply matching or integrating the changes on the new branch we create to the changes we have on our develop branch to save us from conflicts.

Rebasing is the process of moving or combining a sequence of commits to a new base commit.

git commit -m “commit message”

This is used to write a commit message, that you can always fall back on. An image of all the (tracked) files in your directory are captured in a commit to a git repository. Please note, it is always good to write a description message for the commit in case, if there is a need to roll back to a commit.

git checkout -b “branch name”

Before now we do a checkout to the development or main by using git checkout <branch_name> which will take you to that branch. And now we can create a new branch with just one command git checkout -b <new_branch> This will create a new branch based on the branch you are already in and it will give a message if this branch already exists. Sample of the message: A branch named <new_branch> already exists. With this new 2-in-one approach this git command saves us from a lot of stress

git checkout -B <new_branch>

This git command will create a new branch. But kindly note: If this branch already exists it will reset it, so to be on the safer side it is advisable to use git checkout -b “branch name”.

git branch -D “branch name” or git branch -d “branch name”

There is a slight difference between git branch -D “branch name” and git branch -d “branch name”. Just like how we have the git checkout -b “branch name” and git checkout -B <new_branch> likewise is the difference here, the one with D is to delete the branch from the remote repository permanently and the other one with d is to delete the branch from local.

git config

Git Config is actually bigger than what we see or basically, it is a multiple-purpose command and we will be looking into some of its views.

//add username
git config --global user.name "your_username"

//add email
git config --global user.email "your_email_address@gmail.com"

//check configuration
git config --global --list

git config --global user.name "Adejoke Ogundipe"

git config --global user.email a14@gmail.com

git config --list

git config --list --show-origin

git config --global --edit

//Get system value
git config --system --get https.proxy

git config --system --get http.proxy

//Get global value

git config --global --get https.proxy
git config --global --get http.proxy

Please Note: All these were extracted from google.

git init

Using the git init command, a new Git repository is created. A new, empty repository can be started with it or an existing, unversioned project can be converted to a Git repository. This is typically the first command you’ll perform in a new project because most other Git commands are not accessible outside of an initialized repository.

git add.

A modification in the working directory is added to the staging area using the git add command. It instructs Git that you wish to add updates to a certain file to the upcoming commit. Changes aren’t truly logged until you execute the git commit.

git checkout <branch_name>

This command is used to navigate to a different branch from the current branch.

git status

The status of the working directory and the staging area are shown by the git status command. It enables you to view which files Git is not tracking and which changes have not been staged. You won’t find any details about the history of the committed projects in the status output.

To learn git in and out, I will recommend you please click the links below

Thanks for learning with me, I will always keep you posted and kindly drop comments on the commands you do use. I’m open to learning new things and I await your comments. Thanks once more and I have a bonus link for you if you are interested in learning algorithms. Kindly go to the link below. I will be writing about them one of these days.

--

--

Adejoke Ogundipe

An explorer of tech world, a learner, an epigrammatist and a rare gem..