DEV Community

Cover image for Git Explained: Proper Team Etiquette

Git Explained: Proper Team Etiquette

Milu on May 23, 2020

Proper team etiquette will assist your team to achieve seamless collaboration and productivity. These rules are often gained with experience as mos...
Collapse
 
pauljherring profile image
PJH

Just wondering why all the git commands in the code blocks start with a capital G, yet the touch command in them, and the git commands in the Handle Large Files section start with lower case...?

Collapse
 
milu_franz profile image
Milu

I write my drafts in a google doc and didn't realize it capitalized those Git commands. I updated it! Thank you for pointing that out!

Collapse
 
bryanloeper profile image
Bryan Loeper

Great article, I'll be sharing with my developers! One thing that stuck out though is that there are different philosophies out there for origin/master and devs may run into repos where that branch is what is deployed rather than ready to deploy.

Collapse
 
milu_franz profile image
Milu

That is a great point Bryan! I edited my post to include both possibilities. Thank you for the suggestion :)

Collapse
 
thebouv profile image
Anthony Bouvier

Love this article and plan to share it with others, but the token naming part has me stuck. I've actually had several issues with other non-git software that interacts with branches that have / in their name. So we name things feature-, bug-, etc instead of feature/, bug/. Jenkins for instance seems to break on the / naming convention and I know I've run into problems in other software too.

Collapse
 
milu_franz profile image
Milu

That is a really good point Anthony! I've updated this article to suggest any of those name conventions (using / or -) and added a note for the ones that are using Jenkins or other third-party tools in their CI/CD implementations. I'm glad you brought this up as I haven't encountered this issue in the past. Mostly because my team uses Gitlab CI and thankfully / do not affect our pipelines.

I'm glad you enjoyed this article and thanks again for the suggestion!

Collapse
 
marianban profile image
Marian Ban • Edited

Thanks for putting it together. git fetch --prune --all is a very useful command and it is also possible to automate this process with git config remote.origin.prune true It deletes branches when you do a git pull/fetch if they were deleted on the remote.

EDIT: Actually I misunderstood the prune command a bit 😅 The prune option will only delete remotely deleted references in your working tree under remotes/* . Your local branches will be kept and you have to still delete them manually with git branch -d.

Collapse
 
aerosoul profile image
Daniel Liuzzi

Or simply git config --global fetch.prune true if you want this in all your repos.

Collapse
 
milu_franz profile image
Milu

Nice! I haven't you used that configuration before. I'm excited to try it out :)

Collapse
 
jsn1nj4 profile image
Elliot Derhay • Edited

Nice article summarizing some good practices!

Also wanted to add there's a newer way to delete a remote branch.

git push --delete remote branch-name

This was added I think because it could be easier to understand and remember.

I'll note though that, at least in my experience, it doesn't let you tab-complete the branch name if you delete the local branch first. But it will if you delete the remote branch before deleting the local one.

However, if you do delete the local branch first, using the other method you mentioned will still let you tab-complete the remote branch name.

Not sure why tab completion doesn't work with the new way of deleting remote branches, but oh well... 🤷‍♂️

Collapse
 
milu_franz profile image
Milu

That is a great point, the branch deleting command you added is definitely easier to understand and remember. I added your suggestion to the post, thank you for bringing it up!

In regards to the issues you are having with tab-completing a branch name, I’m not sure why bash git completion does not recognize those two commands as the same, I will look into it and let you know if I find out why this is happening.

Side note, starting on Git v2.8.0 you can use git push with the -d option as an alias from —delete, in case you like this shortcut better.

Thank you again for reading and providing suggestions! :)

Collapse
 
jsn1nj4 profile image
Elliot Derhay • Edited

Oh neat! That'll be even nicer. :) Thanks!

Collapse
 
damsalem profile image
Dani Amsalem

Another great article Milu! I have a question and a suggestion:

Question: What is --list in this line of code git branch --list “feature/*”? It looks like it might be the name of the branch. I went back to your earlier article Git Explained: The Basics and didn't notice a naming technique for creating new branches. Whereas, this Atlassian article on branches doesn't use any hyphens to prepend a branch name.

Suggestion: I noticed your list of previous posts at the bottom, would you mind being redundant and adding them to the top as well? I'm saving these and having a quick reference as to sequence, above the fold, would be very handy.

Collapse
 
milu_franz profile image
Milu • Edited

Hi Dani!

The command git branch or git branch —list shows you all the branches you are keeping up with locally. You also have the option to give this command an argument in order to only see a group of branches. For instance, if I followed the token advice mentioned in this article, I should have some branches that start with feature/name-of-branch and other that start with bug/. If I want to only list all the branches that add a feature and ignore all the bug branches, I can give it an argument that asks for all the branches that start with feature/* (the asterisk is like a wild card).

I hope this explanation helps clarify that command.

Also, thank you for the suggestion, I didn’t know this before you mentioned it but you can do a “series” of posts and they all link to each other at the top of the page. So I took care of that :) Thank you!

Collapse
 
damsalem profile image
Dani Amsalem

Right on! Thanks for the detailed explanation of git branch and for making this into a series :)

Collapse
 
zkoppert profile image
Zachery Koppert

Love that you pulled all these great practices together. Thanks for the reminders and new info!

Collapse
 
milu_franz profile image
Milu

Thank you for the kind words Zachery! Glad you enjoyed this post :)

Collapse
 
vishnubaliga profile image
Vishnu Baliga

Very informative and well written!

Collapse
 
milu_franz profile image
Milu

Thank you Vishnu!

Collapse
 
hp profile image
Hari

Thank you for this very informative article on Git. Appreciate it! :)

Collapse
 
milu_franz profile image
Milu

Thank you for the kind words Hari! I'm glad you found it helpful :)

Collapse
 
joshangehr profile image
josh_

Really nicely done, thanks for this. The illustrations are beautiful!

Collapse
 
milu_franz profile image
Milu

Thank you Josh! I really appreciate the encouragement and kind words :)

Collapse
 
circleofconfusion profile image
Shane Knudsen

Thanks for this. Learned a few tricks I didn't know.

Collapse
 
milu_franz profile image
Milu

That is fantastic! I'm glad this post was helpful to you Shane! Thank you for reading.

Collapse
 
kn_sandeep profile image
Sandeep Kongathi

I like the pictures Milu, where did you create? tool/software?

Collapse
 
milu_franz profile image
Milu

Hi Sandeep, my illustrations are done using an iPad and an app called Paper Pro. Glad you like them!

Collapse
 
gerardolima profile image
Gerardo Lima

using "/" as part of the branch names may look cool, but will definitely causes trouble on CI / CD pipelines.

Collapse
 
rinkattendant6 profile image
Vincent

I suppose that depends on your CI/CD tool. At my work we use GitLab CI and it works well, in fact one of the teams has the tool configured to run certain jobs based on whether the branch is a feature branch or pre-release.

Collapse
 
milu_franz profile image
Milu

Same here Vincent, my team uses GitLab CI so I haven't experienced any issues using / in our branch name conventions.

However, that is a good thing to note as other teams have different implementations. I added a note for it Gerardo. Thanks for the suggestion!

Thread Thread
 
gerardolima profile image
Gerardo Lima

When the application is containerised, having this convention will make it not feasible, for example, to have images tagged by its code branch. It's not a showstopper, but the kind of small nuisance that takes time.

Collapse
 
milu_franz profile image
Milu

That is such a great resource! Thank you for sharing, Rob!

Collapse
 
hugodahl profile image
Hugo Dahl

Great tips Milu, will be sure to share these with team members and people I know who might be CLI reluctant.

To take Rob's tip one step further, Github has a helpful site to generate a .gitignore file for a number of platforms and languages in one step - gitignore.io. They even provide an API of sorts, so you can stay in the command line the whole time!

Thread Thread
 
milu_franz profile image
Milu

This is such a cool tool Hugo! I'm planning to use it in my projects from now on. I added it to the post so more people learn about it. Thank you so much for sharing :)