4
In my work it is very common to switch between Feature branches and Stage/develop branches several times during the day. And many of these times I need to write or use a tab to complete the branch name even though I’m inside it. I wanted something that would act in a similar way to a this
in programming: a reference to the current branch name.
Problem:
$ git checkout -b feature/nova-feature
// aqui eu trabalho na nova feature ate ficar ok
$ git push origin feature/nova-feature (*)
$ git checkout stage && git merge feature/nova-feature (*)
$ git push origin stage (*)
$ git checkout feature/outra-feature
// trabalho em mais alguma coisa
$ git push origin feature/outra-feature (*)
$ git checkout stage && git merge feature/outra-feature (*)
$ git push origin stage (*)
etc
In 8 interactions with the git
i had to write 6 times the branch name I’m on (in 3 different branches).
What I already have today in my . gitconfig
[alias]
mg = merge --no-ff --no-edit
mc = commit -a --no-edit
df = "!git diff --color | diff-so-fancy"
ck = "!git checkout $1 && git pull origin $1"
gr = "!git branch | !grep $1"
msp = "!git ck $1 && git mg $2 && git push origin $1"
ck
, gr
and msp
are aliases that allow me to write only the branch name once when I concatenate.
What I wanted:
$ git checkout -b feature/nova-feature
// aqui eu trabalho na nova feature ate ficar ok
$ git push origin this
$ git checkout stage && git merge this
$ git push origin this
$ git checkout feature/outra-feature
// trabalho em mais alguma coisa
$ git push origin this
$ git checkout stage && git merge this
$ git push origin this
So that I could create alias
for these most common actions that work on any branch, without having to write the name. There is a way?
see if this helps you https://www.reddit.com/r/git/comments/1v16qc/how_do_i_reference_the_current_branch_in_a_git/
– Giovane
This can help your flow a bit: if you want to go back to the previous branch, you can use
git checkout -
– Dherik
Perfect, I’ll delete my comments from here so don’t leave mess in your post.
– Bacco