DEV Community


Posted on • Originally published at on

Git workflow and my new love of Git alias

For good or bad, my current Git workflow does not include merges, but rebasing.

It keeps the history cleaner, works with the established workflow (pretty standard GitHub flow) just no merge commits. I was trying to find a nice graph of the master branch, but coming from a GitLab background it isn’t hard to find this information in the GitLab repo, but I don’t think GitHub really has this history feature. Anyone know the best way figuring out the history on GitHub?

We really enforce making sure to have meaningful commits, and commit messages. When you are working on your local branch, feel free to commit away, but an interactive rebase is needed before requesting your pull request. After you have done a couple of these rebases, there really isn’t anything to be afraid of. I hadn’t done one, and let me tell you, my first pull request was pretty painful. I think getting through the review process on that, and getting my commit history clean took just as long as coding my feature >_<. Now me, rebases, and amends are friends. I haven’t had a chance to use fixup commits yet, but they are something on my raider to try out soon!

I enjoy using Git bash for my source repository needs. Even with my more advanced workflow at my company, for me it has the most flexibility. I have given Sourcetree (works better with BitBucket then GitHub) and Git Kracken a try before, and it is nice to have visuals when you need to deal with complex conflict situations, but I keep on going back to my trusty Git Bash. I never used to be a command line person, just in certain situations, but now especially since I have switched over to Ruby and Rails I have at least 3-4 terminals open at anyone time. I even exited Vim yesterday without having to look it up! I feel that should be some sort of milestone.

Also I have been making use of GIT CLI alias, also installed multiple scripts to run in the terminal (terminal parrot I’m looking at you!). Some of these help me with my job more then others :). If you don’t have a git alias, get yourself one stat. You just need to add lines to ~/.gitconfig

    st = status
    ci = commit -v
Enter fullscreen mode Exit fullscreen mode

Some of my personal favorites right now are:

st = status

co = checkout

dm = diff –patience master

prb = pull –rebase

pu = pull –rebase origin master

pf = push –force-with-lease

po = push origin master

What’s in your Git alias? And also how awesome is Command+Option+Shift+V on MacOS? That was the key to my problem with copy and pasting text and not keeping the old formatting!

Top comments (24)

marsavela profile image
Sergiu Marsavela • Edited

And why not just shell aliases instead? Unless you're switching between shells, I don't see the point of using git st rather than gs or gst...

adarshkkumar profile image

I use oh my zsh and git aliases that comes along. But at times type in the whole command atleast once in a week so I don't forget them.

rad_hombre profile image
Matthew Orndoff • Edited

Whatever floats your boat.

I like git aliases because they help with separation of concerns and keep my .aliases file a little less bloated.

ackvf profile image
Vítězslav Ackermann Ferko • Edited

You can display version history on github in Insights/Network.
github graph

I don't agree with fast-forward merges aka rebase with no merge. For me, a branch is a separated idea and master is a collection of references to those ideas.

I understand that a flat (rebase) git-flow with history manipulation makes sense for usage with git in bash where the commit history is displayed in a linear fashion. However, I don't agree that this approach is better, compared to a two dimensional (merge) git-flow in a visual git. Also changing the Feature's commit history even slightly makes it difficult, for a reviewer, to understand your mind flow and reasoning.
I was on a project, where everyone squashed their branches to a single commit before rebasing onto a master and I can tell you, you don't want to review this.

rebase flow

Compare with this
(BTW, you can always use --first-parent to hide branch commits.)
merge flow

An excellent quote from etcwilde

Another issue is fast-foward merging. Many people are afraid of merge commits, and without a good visualization merge commits just complicate things, so they do fast-forward merges. Yeah, it gets rid of the merge commits, but since branches are usually separate ideas, the merge commits are like the separation of paragraphs. Yeah, you could write a book without paragraphs, but it will suck. Don't do that to your repositories, or they will suck too.

cseeman profile image

Excellent points! I am actually in favor of merge commits, but my teams current workflow does not use them. It's something that I would like to try and get added into our git workflow, but we'll see ¯_(ツ)_/¯

The quote from etcwilde is a great example! Also thanks for pointing out where the visualization was at on gitub, just kinda wish it had a great commit range on it.

pkristiancz profile image
Patrik Kristian • Edited

Nice. Hey, give —fixup commits a shot. after while commit messages are like “fixup: fixup: fixup: feature” , but after interactive rebase it is all nice.

Ad aliases: i am not friend of them, i try to use as little as posible of them, because when ine use aliases, it make him forgot command it stands for.
i only use my “git tree” to pretty oneline log and some forcepushes to specified branches
edit: here are my only aliases:

list = log --oneline --decorate -n
tree = log --oneline --decorate --all --graph -n
deploy-dev = push origin HEAD:_dev -f
deploy-prod = push origin HEAD:_prod -f
deploy-both = !git deploy-dev && git deploy-prod

if i should have onyl one, it is tree

mariocd10 profile image
Mario DeLaPaz

I agree, we'll get used to our own environment and then when we use someone else's we forget what the commands stand for.

The ones you listed seem to be the 'basic' aliases you should have to make your work easier.

pkristiancz profile image
Patrik Kristian

Yes! :) exactly...
you are on another computer (your prod server) and you need to do something in git. if you use all heavy aliases, then you just can't do anything, because in fact, you do not know how to git :D :)

yes, listed ones are absolutelly basic for me

devcamilla profile image
Camilla Santiago

My new favorite alias is fixup --amend. Lets you amend to a specific commit, not need to be the latest one.

fixup = "!f() { TARGET=$(git rev-parse "$1"); git commit --fixup=$TARGET ${@:2} && EDITOR=true git rebase -i --autostash --autosquash $TARGET^; }; f"


cseeman profile image

Thanks for sharing, this is definitely something I will be checking out.

bgadrian profile image
Adrian B.G.

Here is ...everyone else aliases, that uses bash-it I mean.

I'm tired to say what is wrong in having custom personal aliases and shortcuts, instead I just give this link :))

enguerran profile image
enguerran 🐐💨 • Edited

The first git alias I would like to share is git aliases:

aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /' | sort

The one I could not live without is a git log alias:

lola = log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all

I often use a git oops and a gwip and gunwip (available in git plugin for oh-my-zsh):

gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify -m "--wip-- [skip ci]"'

gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
oops = commit --amend --no-edit

And the very classical gapa and gst:

gapa='git add --patch'
gst='git status'

(note: some are git aliases, some are bash aliases)

nivesh002 profile image

oh-my-zsh has the coolest git alias ever.

  • gst : git status
  • ggpush: git push origin master
  • ggpull: git pull origin master
  • glo

Complex ones but handy

  • glog
  • glol
moopet profile image
Ben Sinclair

I don't use any git aliases because I don't like to rely on them on foreign systems. At odds with that, I have a bunch of wrapper scripts which are workflow- or project-specific which I use all the time :)

felzan profile image
Luís Felipe Zanatto Alves

I use the alias from git plugin (oh my zsh)
gst for git status for example
It's pretty cool

leydsonvieira profile image
Leydson Vieira

Congrats for the great post Christine!! I loved it

jstocto profile image

Agreed. But you then also need to merge with --no-ff to avoid polluting your master. Renaming for public branches rebase is also a must to avoid push force drama.

jstocto profile image

For aliases and shell/git configuration, a few pearls:
with oh-my-zsh/git and others according to your tastes. (♥ gloga)

--rebase by default on git pull is comfortable too.

jstocto profile image

And obviously for those that didn't know it:

nickytonline profile image
Nick Taylor

Thanks for the post Christine. We rebase where I work as well. Here's my aliases,

cseeman profile image

Ooh nice, I think I will add a couple of these onto my file too!

kungtotte profile image
Thomas Landin

I like prettying up the log to make it a bit more palatable, here's an example (not mine).

chijos profile image
Chirag Joshi

I did not know about ‘git diff --patience’ until today. Thanks Christine!
I have a few aliases that I find useful.

ramlev profile image
Hasse R. Hansen