Git Commands

In this post, will be discussing the various git commands that are very helpful to a developer in daily life

git init — Create a local repository

git clone — Create a local copy of the remote repository

git fetch — Fetch the remote changes into the local repository

git rebase — Bring your changes on top of remote changes (usually preferred way of doing it after fetching remote changes — a safe way to do it. When executed after git fetch -result will be like git pull)

git pull — Bring remote changes to your local working branch

git branch — Lists local branches (git branch -a lists both remote and local branches)

First checkout the branch using : git checkout -b <local_branch_name>

This will create a local branch.

Now create a remote branch by pushing your local branch to the remote.

git push -u origin <local_branch>:<remote_branch_tobe_created>

git checkout — Check out a branch and switch to that. When checking out remote and create local branch -use git branch -b)

git status — Display the current state of the current branch. This command displays what files are committed, what files are new, and what has already added

git add — when done with changes, add them to the local staging. One step before the git commit.

git add . (adds all the changes)

git add -u (adds only the edited/updated files)

git commit — Creates a local commit on the working branch. Usually commit with a commit message using git commit -m “commit message”

git push — Push the local changes to remote.

If tracking is established, git push will push the commit(s) to the remote

Otherwise use — git push origin master(whatever branch you want to push)

git merge — Used to merge multiple branches. Stay on the branch you want to merge and then use the incoming branch name to merge the incoming change into the branch you are on.

git merge <incoming_branch>

git log — Display the commits on the current branch

Limit the last “n” number of commits: git log -5 : this will display the last 5 commits

git stash — Save your work onto a temporary area. This can be popped back into the working branch if there is some conflict and needs resolution.

PrettyPrint the logs lines — now you can use git lg or git lg -5

git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

--

--

--

Technology Enthusiast

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

10000-foot view of Consensus in Distributed Systems

WHAT DOES I DO AS A DESIGNER IN RAION HACKJAM 2019?

Expenditure Application with Attractive GUI

Build-Test-Deploy with Kubernetes (CI/CD)

Linked List Questions and Solution (Taken from leetcode : pasting verbatim)

Shadow IT Solutions — 3 Things You Need To Know About Shadow IT

Kafka — Rebalance

The relationship between product engineering and product management

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ramakrishna Chintalapati

Ramakrishna Chintalapati

Technology Enthusiast

More from Medium

Implement the concept of template and Do while loop in python

Git Flow — Helpful and Simple

Software architects and engineers or just artisans?

Git: The Revolution In DevOps