Git day-in and day-out

Indira Raghavan
3 min readOct 19, 2020

Everyday commands at a glance

Here is a list of Git commands that might be useful for daily work along with how they work:

  1. Let’s start with cloning a repository:
just to clone a project:
$ git clone https://clone-url-for-the-project.com
Clone a project into specific folder:
$ git clone https://clone-url-for-the-project.com "c:/path-to-your-folder/"

2. Branches:

create new branch
$ git checkout -b my-new-branch-name
checkout existing branch
$ git checkout existing-branch-name

3. Working with changes:

check the files changed
$ git status
stage all changes
$ git add .
commit the changes
$ git commit -m "your-commit-message"
push changes to origin
$ git push

4. Get latest:

get the changes for the branch you are in
$ git pull
pull another branch into your local
$ git pull origin other-branch-name

5. Abort merge or Rebase:

If and When pull from different branch was a mistake. For more details on when to Merge or Abort, click here

if there are merge conflicts, you will have a branch name with MERGE or REBASE attached to your branch name:$ git pull origin other-branch-name
Resolve the conflicts
c:/Workspace/Project(my-existing-brnach|MERGE)
$ git abort --merge
or
c:/Workspace/Project(my-existing-brnach|REBASE)
$ git abort --rebase

6. Reset commits:

wish to reset all of your commits
$ git reset --hard HEAD
wish to remove just last 2 commits
$ git rest --hard HEAD~2
if you want to know how many commits to undo
$ git log
choose number based on the log of commits

7. Reconcile your repository and branches:

IDE keeps information about all your previous branches. Even if the branches were deleted from origin. To update your information.

$ git pruneif you wish to check what information is missing
$ git prune --dry-run

Prune command is especially useful when you are trying to switch to a branch but your shell doesn’t know the branch exists. You can also do git pull on your existing branch to get the latest for the repository.

8. Stash your changes:

wish to keep your changes that are not ready to be committed
$ git stash save your-stash-name
to apply the stash back
$ git apply stash your-stash-name

9. Cherry-pick:

To pick and choose commit hashtags for the new branch:

do a git log on the branch to get the commit SHA
$ git log
output will be something like this:
commit 255dac3....... (HEAD -> branch, origin-branch)
Author: Indira.Raghavan <your-email>
Date: Tue Oct 13 18:10:26 2020 -0400
choose the exact hash you need for your branch:
$ git cherry-pick <commit-SHA)

In conclusion:

Command line inputs are all in the now, everyone is using them. IDE’s are working on making it easier to provide UI tool that does all of these functions(often more intuitive) without command-line inputs. It is your preference to use the CLI instead of GUI. If you do wish to use the CLI, hope this article helps you with day-to-day commands.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Indira Raghavan
Indira Raghavan

No responses yet

Write a response