Hi, I'm Jason McCreary. I go by JMac.
I'm a full stack and iOS developer who likes building products and services. Recently this includes services like Laravel Shift and Getting Git.
I've been programming for 20 years. I'm very passionate about what I do and lately I've been on a mission to empower developers to master Git. So I'm glad to answer any and all of your Git questions (or anything else).
My AMA will start at 2PM ET today, September 13th, so please feel free to Ask Me Anything!
Oldest comments (102)
What's your greatest personal frustration with learning Git?
Also, any common problems/patterns about Git that your students run into when learning?
I think visualizing the tree takes time to master. Once you're able to see the commit tree in your mind, it's easier to forecast what each command does.
Something else, a little more advanced, is to realize that everything is just a reference. A
commit
,branch
,tag
, evenstash
all simply point to some changeset in the.git
folder. This also helps visualize the tree as well as understanding the various commands that accept a reference as an argument.In the beginning, I recommend keeping is simple. Just use
add
andcommit
. Don't worry about the other commands until you need them. And never be afraid to ask your local Git Master or me on Twitter - we all started as beginners.That's a great point. Once I started picturing the git tree it really made a lot more sense.
On this note, how much is mastering git different from other parts of software development? Like, is learning to visualize the tree different from visualizing the structure of an application or data flow?
True, not much is different.
As with anything, it's all about experience. You have to push yourself to fully understand the problem and try new solutions. Many developers just do what they know, and in this case, only scratch the surface of Git.
I'm definitely guilty of continuing to grow my skills in most areas of software development, but only doing the minimum in advancing my deeper understanding of git. Something I plan to fix 🙃
This comment mad me think of your recent post Ben.
The myth of "never going back to fix it later" 🤣 so did you fix it?
What is your take on Continuous Integration and Feature Branches? Do you think Feature Branches inhibit CI?
I haven't experienced any issues where feature branches inhibit CI. However, I can envision it becoming complicated at scale. That is testing multiple feature branches in isolation would require many environments.
Typically I work quickly. So I don't build individual feature branches. They go through code review and testing before being merged into
master
. Then they are deployed.I have worked on teams that build sets of features. Normally their CI job has the ability to easily switch the source branch.
IRT CI and multiple envs to test feature branches, isnt there a way to segment an existing env to host a particular feature and then using existent LLs compare the results thusly? understand if this would be marked OT.
What factors most affect the best git workflow for the job? Team size? Business goals? Tech choices? Personal preference?
I always start with GitHub Flow. I find this
master
/feature branch workflow to be the easiest to manage.In the hundreds of repositories I've managed, Git Flow on a small handful - like 3. These are normally projects that either need to support multiple versions (e.g. v1.0, v2.0, etc) or the business is unable to release features as they are complete (e.g. works to hard deadlines).
I'd challenge the latter is usually not a Git issue, but a deployment issue. As such, you may still adopt a GitHub Flow workflow.
Hi Jason, thanks so much for sharing your knowledge! I was wondering - how do you feel about interacting with git via the command line versus a gui like Github Desktop/GitKraken/etc? Do you prefer one or the other personally?
Command line all the way!
Do you see any use of GUIs? I personally find I benefit from the visual component when I want to verify changes to avoid mistakes. While you can do this on the command line, I much prefer a visual tool.
Does this fall in the category of evil wizards?
I think if it's a tool that helps you do something more efficiently, then great.
I'll use a visual tool for diffs or complex tree visualizations. But really that tool is just GitHub.
It's when you're using a tool to do something you can't do on your own, then it falls into the category of evil wizards.
I love using
git add -p
ever since @maestromac told me about it, but I find myself using Atom's Git integration to pick out a few lines of changes I needed to discard. Also, their merge conflict handling is extremely easy to use.Haven't touched their GitHub integration at all though.
What are you trying to learn next, as it relates to git?
I want to learn more of the options for
log
. There are so many and virtually infinite combinations. These can be useful reporting on all sorts of thing in your code - not just recent commits.I'm also interested in finding workflow alternatives to Git Flow that solve the requirement of scheduled release timelines.
While Git is the tool I use every day, I feel that I'm using less than 30% of Git's full functionality. What is the best way for me to get acquainted with the rest of Git's features?
This really depends on your workflow. For example, if you're a solo developer, not sharing your work, you have no need to use commands like
push
,pull
,remote
.In the end, you have to push yourself to use Git. For example, if you find yourself throwing away work or spiking out ideas, use feature branches.
Personally, I've adopted a workflow of using
git add -p
+git reset --hard
. There's no reason I need to use these commands. I could just as easily use Cmd + Z. But I find it's faster with Git. I write all my code, add what I want withgit add -p
(leaving out what I don't want). I make the commit, then discard what's left withgit reset --hard
.I would advice against "you have no need to use commands like push". The push command is your backup.. :)
You misunderstood. Please read the full comment for context.
Magit in emacs is a pretty good way to learn of other gut options and parameters.
What's the most common mistake people make when using git?
What's one thing everyone should make use of with regard to git, but (almost) no one does?
Often when things go wrong, we resort to deleting our local copy and recloning the repo. This is going to happen in the beginning, especially when we just need to get something done.
I think this is a mistake. That is you need to learn what went wrong. If nothing else, look at your command history and try to replay them to recreate the issue and determine what went wrong. Bottom line - don't deprive yourself the learning opportunity.
I don't think many people respect the
git add
process. Many just add everything. As a developer, I like the opportunity to give my work a final review before I share it with my peers. So don't rush, usegit add -p
.Git used to be notoriously bad to manage binary files. What is the current situation with that?
I haven't leveraged Git to manage many binary files. Maybe someone from the dev.to community could chime in on this one.
You could use a .gitattributes file in the root directory of your repo to explicitly mark the file as "binary", see this link git-scm.com/book/en/v2/Customizing.... This should improve diffing!
Any book/website that you reccomend?
Of course I recommend Getting Git. It's a video series I created which covers nearly all of the core Git commands in two parts (basic and advanced usages). It's organized in four sections that build upon one another to take you, literally, from
git init
to Git Master.However, outside of this, I recommend reading the first few chapters of Pro Git. This is something I do every few years and I always learn something.
How to understand source code of git and where to start?
I honestly have not dug through the source code. I find browsing around the
.git
folder was enough for me. But if you were so inclined, the source is mirrored on GitHub.Would you recommend a shop that is using the TFS Version Control System to switch to a TFS git repo? And if so, how would you make the argument? Keep in mind nearly all that would end up using it are unfamiliar with git so they would not have expertise.
I recently undertook this at our company. Admittedly, there's only 2 of us, which simplified things.
I would suggest that the basics of git are very easy to grasp. It's not hard to transition from another VCS if all you currently do is basic push/pull and the occasional branch/merge. IDE integrations make it so that you never have to touch the command-line (for the first little while anyway)
The combination of having a personal copy of the repo, and inexpensive branching really make git a joy to work with and enable stress-free experimentation.
Also, git is a first-class citizen in TFS/VS (maybe even more than TFSVC at this point) so there are no concerns there.
Thanks for the response!
I definitely agree about TFS and git becoming a first class citizen for MS now. Part of my reasoning is that it seems like MS is moving away from TFSVC so it may be inevitable that we'll need to do the switch.
I long for the local commits and easy branching. I use git for everything I do at home/github so it'll be less of a jump for me. I'm just not always great at making a case for these kinds of things at work.
I've done this on a few C# projects. From my understanding, there's little change on the surface. Previous TFS users can continue working via the IDE and users with Git now have the power to use other tools, like the command line.
So, my argument would be it's the best of both worlds - virtual no change for most users, but allows others to have an eye to the future.
I have been suggested to stay away from ‘rebase’ by one of reputed software consultant who has GDE certification and authored several pluralsight courses. What is your take on that comment? I know I’m being very generic without including any scenario or examples. However is there any example situation in which you would recommend not to use rebase?
The reason people shy away from
rebase
is because it rewrites history - meaning it changes the commit SHAs. So if you're sharing your work with others, that can be a problem.It's likely this consultant was the victim of a force push and made a sweeping statement to never use
rebase
again. We've all been there. It's frustrating.Being mindful of which commands, like
rebase
, can rewrite history resolves this issue. Then you can use it appropriately. For example, I userebase
often. But I do so at the end - right before merging - so I limit the chance for it to affect other developers.How would you recommend setting up a project that has multiple developers with Git, especially if you want to make sure that a rogue developer can't check in commits as another person or take the whole origin down?
Give them limited access (read only) and setup a code review process. Nearly all services - GitHub, Bitbucket, Gitlab - provide ways to restrict write/push abilities to branches.
For example, our team creates their own forks of the main repo. We also protect branches like
master
which prevents anyone from pushing directly to it without a Pull Request.We're finally moving to git from a dev/production server for website maintenance. I've used git before, but never set up workflows, etc.
2 q's :
In the Git Flow - Is there a way to maintain the development branch on one subdomain while the master branch is on another?
Is there a good method for tracking (and ignoring certain?) changes to databases?
I'm not sure I understand the first question.
As far as the second, are you tracking the entire database (structure + data) in Git? Or just migrations?
Hi Jason, thanks for your reply
2 - would prefer to track the whole database.
1 - Our current workflow uses a dev/staging copy of the site at dev.domain.com & the live/production site at (www.)domain.com. I'm trying to figure out how to merge that workflow into something close to a Git Flow framework if possible? I know I'm not explaining this well at all :\
For anyone who finds this post - worktrees were the answer to #1.
This was the ultimate solution: github.com/ferkungamaboobo/firmida...
I've been programming since around 1980 but generally on my own, either as the sole dev or mostly on my personal projects. Make files back in the day and RCS for the past 20 years so I have some familiarity with revision control. I've had a difficult time finding a git book that is helpful for someone like me who is familiar with RC but doesn't work with a team so haven't experienced the problems teams experience. The books seem to come from a more team and professional development environment than what I do. As a Systems Engineer, I'm working on DevOps methods which means becoming involved in the dev side of the house and CI/CD.
To the question, do you have a suggested book for someone like me? That I can take my RC experience and use it to leverage learning and using git.
It sounds like your challenge isn't so much learning Git, but leveraging some of its shared aspects. For that, I would recommend finding an open source project on GitHub and try to contribute to it. This will give you the chance to use commands beyond
add
andcommit
.For resource recommendations, see my previous comment.
That is possible. I've picked up some of the basics from one book (Jump Start git); setting up a repo, pushing the code, and cloning. I have a pretty extensive dev type environment using scripts and rsync to be able to sync updates from my dev server to the production servers. I was trying to take my manual, and a little hacky, process and use git, gitlab, and jenkins to automate the process. The branching and team aspect is what's new to me and where I'm stuck a little. Working on this will help me be familiar with CI/CD and the development to QA to prodlab to production path.
I appreciate the link to the video site. I have a subscription to Safari Online Bookshelf. Perhaps the videos are there already :)
Thanks!