DEV Community

Pavel Movchan
Pavel Movchan

Posted on • Updated on

Daily git usage

Hi guys!
We all use Git every day typing commands such as git push origin master many times a day. But maybe you have aliases contracting to git p. Gradually, it becomes more irritating.
For example I use the git push origin {branch} command about 20 times a day. git commit -m "{message}" maybe 15.

I don't like the built-in Git tools into IDE's and don't use them at all.

So I've decided to automate some of my work.
I wrote a script that helps me every day and, I hope, will help you.

Called casual-git.

How it looks

myproject master โžœ gh

  d  - push
  f  - push --force
  p  - pull
  o  - pull --force
  c  - commit
  a  - commit --amend
  s  - commit --smart
  l  - log --pretty
  h  - checkout --smart
Enter fullscreen mode Exit fullscreen mode

Almost each of the commands I use every day.

It's really easy to use!

It is especially helpful if you name your branches with long names like feature/EGNYTE-20-watermarks-over-documents:

  d  - push
  f  - push --force
  p  - pull
  o  - pull --force
  c  - commit
  a  - commit --amend
  s  - commit --smart
  l  - log --pretty
  h  - checkout --smart

  Enter a branch name or a part of name: ma

  More than one git branch were found. 
  10 first branches are shown. 
  Please choose a desired branch. 

  [0] feature/EGNYTE-20-watermarks-over-documents
  [1] master
  [2] masterfix/EGNYTE-21-big-files-merge
  [3] masterfix/EGNYTE-26
  [4] masterfix/EGNYTE-29-big-files-merge
  [5] masterfix/EGNYTE-33
  [6] masterfix/EGNYTE-41

Switched to branch 'feature/EGNYTE-20-watermarks-over-documents'
Enter fullscreen mode Exit fullscreen mode

Or paths to the files are too long and you need to commit only few of them:

myproject feature/EGNYTE-68-progress-bar-for-watermarking โžœ gh

  d  - push
  f  - push --force
  p  - pull
  o  - pull --force
  c  - commit
  a  - commit --amend
  s  - commit --smart
  l  - log --pretty
  h  - checkout --smart

  Delete files from the next commit:
  No staged files

  Add files to the next commit:
  [1] modified:  app/Http/Controllers/WatermarkController.php
  [2] modified:  app/Jobs/Egnyte/PublishWatermark/Job.php
  [3] modified:  app/Services/QueuedMessage/Queue.php
  [4] modified:  public/css/watermark.css
  [5] modified:  public/js/watermark.js
  [6] modified:  public/mix-manifest.json
  [7] modified:  resources/assets/js/watermark.js
  [8] modified:  resources/assets/scss/watermark.scss
  [9] modified:  resources/lang/en/watermark.php
  [10] modified:  resources/views/watermark/index.blade.php
  [11] modified:  webpack.mix.js

  Enter file numbers separating by spaces: 1 2 3
Enter fullscreen mode Exit fullscreen mode

Github repo

I hope this helps someone!

Top comments (22)

Collapse
 
bgadrian profile image
Adrian B.G.

You are using the force flag everyday, OMG I hope we will not be co-workers ...anytime ๐Ÿ˜

Collapse
 
x0st profile image
Pavel Movchan • Edited

I use the rebase feature every day many times because do not like mess in my git repositories. Of course when I work with other people i don't use the force flag.

Collapse
 
nutondev profile image
nuton.dev

It depends on the circumstances. If he is developing a branch alone and needs to correct his PR and push again for review, what would you do?

Collapse
 
bgadrian profile image
Adrian B.G.

If you want to remove the history you don't have much of a choice, it was a joke.

I would use git merge squash and instead of --force flag I would use --force-with-lease to avoid possible data loss.

Collapse
 
cchileshe profile image
Christopher Chileshe

I applaud this. I think it's great when developers leverage each other's existing tools to simplify common tasks. To me it seems like this tool abstracts the complexities of git commands, why not just use a tool like SourceTree or GitKraken? They are visual tools that do a lot of heavy lifting for you and have imo made my life so much easier. BTW I don't work for either of those nor do I get any kind of compensation from them, but I think they are worthwhile tools if the goal is to make life easier

Collapse
 
x0st profile image
Pavel Movchan

I agree with you about the tools but i use vim a lot and prefer using command line. That's people choice what to use :)

Collapse
 
joshcheek profile image
Josh Cheek

Nice!

Careful with that force flag, though! (I use the that flag less than once a month, but reading your other comments, I also barely ever rebase).

Note that when I use git commit --amend, I use -CHEAD about 90% of the time.

What are the --smart flags? Is that a new feature? I'm on git 2.15.1 and don't see it in the man page, or when I try using them just to see if they work.

For git log --pretty, I spent a day reading the man page, and wound up with a helper, which is aliased to git log --pretty=format:'%Cgreen%h%Creset %Cblue%ad%Creset %s%C(yellow)%d%Creset %Cblue[%an]%Creset' --graph --date=short, it tends to be as terse as git log --format=oneline, but also includes the useful author and branch info of git log --pretty.

Collapse
 
x0st profile image
Pavel Movchan

The smart flags are not built in Git. That's just my 'aliases' for the commands.

Collapse
 
shriharshmishra profile image
Shriharsh

I also have a similar pattern of command repetition. I will try your script. Thanks!!

Collapse
 
x0st profile image
Pavel Movchan

If you need any additional commands, please let me know! I'll try to make your life easier :)

Collapse
 
shriharshmishra profile image
Shriharsh

Sure.. Thanks!

Collapse
 
seankilleen profile image
Sean Killeen

Hey! I've noticed that in this post you use "guys" as a reference to the entire community, which is not made up of only guys but a variety of community members.

I'm running an experiment and hope you'll participate. Would you consider changing "guys" to a more inclusive term? If you're open to that, please let me know when you've changed it and I'll delete this comment.

For more information and some alternate suggestions, see dev.to/seankilleen/a-quick-experim....

Thanks for considering!

Collapse
 
netanelravid profile image
Netanel Ravid

First of all thanks for your sharing
Second, if you are using z shell (zsh, if you are not using it, leaving everything and read about it now, it's amazing!) you can use the git plugin which is super cool
gcam - git commit -a -m
gp - git push
gl - git pull
gb - git branch
gst - git status
It saves me minutes (even hours) a day just using those aliases.

Collapse
 
x0st profile image
Pavel Movchan

I do use zsh :)

Collapse
 
pekhota profile image
Alexander Pekhota

Good job!

Collapse
 
heyay profile image
Ayush

Can you please make a whole cheatsheet with all commands in pdf format?

Collapse
 
gyandeeps profile image
Gyandeep Singh

Nice, thanks for sharing.
I have also created couple of bash helpers to streamline my git workflow: gyandeeps.com/git-helpers/

Collapse
 
ghost profile image
Ghost

Love your script! Thank you so much for sharing ๐Ÿ˜Š

Collapse
 
x0st profile image
Pavel Movchan

Thank you! Make sure to have the most new version :)

Collapse
 
gmaiolo profile image
Guillermo Maiolo

Force command is always one key away and right next to the normal command, I wouldn't recommend that at all.

Collapse
 
x0st profile image
Pavel Movchan

Speacially for you I've added confirmation when using the force commands (:

Collapse
 
emgodev profile image
Michael

Nice! I have been using bash aliases, I hope to learn scripting more.