13 ms·
This is how I git
- globular-toast 6y agoSeems pretty standard to me. Anything notable here?
- manicdee 6y agoIf it’s not particularly contentious maybe it’s a good example for neophytes to follow?
- AshamedCaptain 6y agoStandard for github, maybe.
- k3liutZu 6y agoStandard for other places as well.
- barumi 6y ago> Seems pretty standard to me. Anything notable here? I agree, it's pretty vanilla git usage. I was curious to see any insightful take of whimsical twist, but it boils down to a basic take of good old git flow, which is git 101 for a long time. https://nvie.com/posts/a-successful-git-branching-model/ https://nvie.com/posts/a-successful-git-branching-model/ The only surprising thing in the article was the refusal to use git stash, which can't really be explained on a rational level.
- Cogito 6y agoIt's not git-flow, as all commits are rebased on top of master to make the history of master linear. It is one of the more standard workflows, and it's a concise overview of how the maintainer of curl does their job. For a more complex workflow, I recommend reading the notes from the maintainer of the git project [0]. 0: https://git.wiki.kernel.org/index.php/MaintNotes https://git.wiki.kernel.org/index.php/MaintNotes
- barumi 6y ago> It's not git-flow, as all commits are rebased on top of master to make the history of master linear. I fail to see how that is relevant. I mean, the only possible impact that has is if individual commits within a feature branch are recorded or not, which is arguably irrelevant. You wouldn't get a different workflow if instead of reading you simply did a squashed merge. > It is one of the more standard workflows, and it's a concise overview of how the maintainer of curl does their job. It's gitflow, and leaving out feature branch commits doesn't make a difference.
- Cogito 6y agoI don't know what you think git-flow is, but a linear history it is not. Look at any post on git-flow (or even just the original [0]), and you will see a myriad of merges. Quoting the original git-flow post: > When the source code in the develop branch reaches a stable point and is ready to be released, all of the changes should be merged back into master somehow and then tagged with a release number. How this is done in detail will be discussed further on. The examples further on all use `git merge --no-ff` (ie no fast forward). This is very different to what is described in this post: > When merging fixes and features into master, we avoid merge commits and use rebases and fast-forward as much as possible. This makes the branch very easy to browse, understand and work with – as it is 100% linear. So no, this is not git-flow. [0] https://nvie.com/posts/a-successful-git-branching-model/ https://nvie.com/posts/a-successful-git-branching-model/
- barumi 6y ago> I don't know what you think git-flow is, but a linear history it is not. Your statement makes no sense at all. Gitflow is a workflow. What do you believe it's supposed to be? It's irrelevant how you see commit histories, because with regards to the master/mainline branch it's always linear, isn't it? What do you personally believe gitflow is? > Quoting the original git-flow post: I don't know what you expected to show, but you are only describing a workflow. Changes are made in dedicated branches, and later these changes are merged back into the master/mainline branch in a single commit, which is expected to have been validated and tested and working. That's a workflow. How the log ends up looking is entirely indifernet or irrelevant, isn't it? Again, what do you personally believe is the whole point of a workflow like git flow, specially in light of allowing large teams to continuously integrate their work ? I mean, what do you believe is the whole point of getting devs to work on branches independent of what changes go into master/mainline, and leave merging as a last step that's the responsibility of the developer prposing a change?
- sigjuice 6y agoI gave up on git stash because over time I would end up with too many stashes that I couldn't keep straight in my head. Now I just make temporary branches and cherry pick from them as needed.
- globular-toast 6y agoIt's not git flow. Git flow is horrendous, completely unnecessary and designed by someone who doesn't understand git. The article describes a pretty standard git rebase workflow that is simple and works well.
- etripe 6y agoIMO, git flow came about when people didn't want to or couldn't abandon the idea of trunks in TFS. I've heard its benefits explained as "more security for the business", while in practice it only leads to extra complications and accomplishes nothing a git tag couldn't.
- globular-toast 6y agoYeah, that matches my own analysis. I think it also comes from a time when people considered the source code to be an artifact and creating a source distribution was just checkout+zip. So you'd make a release commit with a version of the source code where the version is hard coded (the git flow page uses a "bump_version" script). Nowadays most projects can build an artifact (source or binary) from any version of the source code and derive their version number from git at build time.
- modderation 6y agoGit Flow actually makes some sense if you need to track and retain history of self-contained fixes and features across concurrent release trains, where "retain history" means more than just a commit message. With that said, I don't think this need is particularly common. Most projects are happier to throw away merge history in favor of a linear history with ephemeral branches and semantic versioning, and that's perfectly fine. The repository layout should be dictated by the project's needs, be it a glorified personal Undo Log, or a management tool on top of a Subversion repository.
- globular-toast 6y agoThat's not git flow, that's just release/maintenance branches. The main feature of git flow is having multiple redundant branches for no reason. Namely a separate develop and master. There is no point of that at all. Look at the diagram, move all tags from master to develop, delete master and rename develop to master. There, you now have the workflow you've described without redundant branches.
- rurban 6y agoThe rational explanation is that branches are much easier to work with. You can rebase and merge branches with your standard workflow, but stashes can only be popped in order. Branches can be reordered and changed at will. As beginner I started with some stashes, but never needed them since. You already got tons of tools for branches, but none for stashes. Stashes are like submodules for me, quirky.
- m463 6y agoThis is more advanced than the git stuff I use - I only use it personally - so it's nice to "read ahead" a bit.
- smokey_circles 6y ago>Never stash Er, no. Right tool for the right job. Whilst I agree that the idea of putting differing lines of work into different branches is great, that's not what stash is for. That's what checkout is for. Stash is used to record the current state of the working directory and index while also returning to a clean working state. I guess for the author, stash is used to preserve changes when pulling in upstream changes you missed. It can, but it does waaaay more. What happens if, like many people, you're working on a few branches at a time. Could be a monorepo, could be a couple long living branches, w/e. What do you do if you've done work against a branch and want to lift and shift to another branch? You could commit and rebase and all sorts of clever mangling of the history. OR you could use the right tool for the job --- Follow up [0] https://medium.com/@yankee.exe/mastering-git-stash-workflow-a310313ca7b6 https://medium.com/@yankee.exe/mastering-git-stash-workflow-... [1] https://git-scm.com/book/fa/v2/Git-Tools-Stashing-and-Cleaning https://git-scm.com/book/fa/v2/Git-Tools-Stashing-and-Cleani...
- stinos 6y ago>Never stash Er, no. Right tool for the right job. Yup. pull --rebase --autostash for example. Technically also stashing, and would be insane not to use it :) More serious note: agreed. I use stashing multiple times a day and never have problems with things being messy. Though I admit I usually look t stashed in a gui, not from the terminal.
- bradstewart 6y agoAnd another episode of "how did I not know git did this". Thanks for this.
- kingosticks 6y agoThe author does explain their alternative to stash (a temporary commit in the new branch that will eventually be cleaned up / removed during 'rebase -i' before pushing) and why that fits with the way they work. Why is stash better than this? Because it avoids the rebase? Many people do this anyway, early commit messages often need rewording. Because it maintains the separate state of the current working directory and the index? Is that it? I don't think that's really a compelling enough reason to claim the author's avoidance of stash is the wrong way to work.
- m4r35n357 6y agoToo much verbing with nouns. Stop it. Also, Git doesn't have pull requests. Did you mean GitHub?
- chx 6y agoI git like this: https://gist.github.com/chx/3a694c2a077451e3d446f85546bb9278 https://gist.github.com/chx/3a694c2a077451e3d446f85546bb9278 A few utility commands and a most important safety net against git reset --hard throwing away work.
- nickcw 6y agoI use almost exactly this workflow with rclone. This bit resonated particularly: begin quote Never merge with GitHub! There’s a button GitHub that says “rebase and merge” that could theoretically be used for merging pull requests. I never use that (and if I could, I’d disable/hide it). The reasons are simply: I don’t feel that I have the proper control of the commit message(s) I can’t select to squash a subset of the commits, only all or nothing I often want to cleanup the author parts too before push, which the UI doesn’t allow end quote Not being able to selectively squash and edit the multiple commit messages is a big missing feature in my workflow.
- secondcoming 6y agoPersonally, I always merge with Github. Never had an issue, and never had concerns about non-linear commit history. So much is made about commit history that I think there are flaws elsewhere in other people's processes, or people are just getting off on their git-fu. But this comment will just descend into a dull, tedious flame war. I don't care. git merge is totally fine.
- scrollaway 6y agoI use the rebase and merge button when the author has clean commits. Otherwise yeah.
- azangru 6y agoWe do squash-and-merge for PRs. Works great so far. A minimal unit of change is thus not a single commit in a PR, but the whole diff introduced with a PR.
- teekert 6y agoLooks like my flow. One thing I do wonder, how do people deal with the tests and the time it takes for a PR to be approved (including tests, discussion, people in different time zones)? I often have interdependent branches (large pieces of related work chopped into small tasks) and take my previous branch along in my new one, this leads to an order in PRs sometimes when a big tasks is followed by a small/fast one. Sometimes I think, come on team, pick up my PR!
- joombaga 6y agoMy PRs sometimes get queued up like that too. Right now I'm waiting to merge an OS upgrade behind a single python package upgrade. I try to anticipate it in sprint planning and do reviews while I'm waiting for reviews.
- Vinnl 6y agoI don't often have that much interdependent work, but if I do, I usually just base the new PR off the old one, and rebase them after the first one is merged. Worst I've experienced is four of those PRs in a row, which wasn't too bad.
- formerly_proven 6y ago> I use git almost exclusively from the command line in a terminal. Is certainly key. Most git frontends seem to be really quite bad for many reasons. Though "Push failed, want to pull, merge and push again? [Yes]" => constant "merged ssh://upstream.server/foo/bar/repo.git merged into branch master" commits being added to the history certainly irks my OCD the most. These frontends also seem to try and hide what git does, which leads to incorrect and confused mental models and much more frustration down the line than just learning to do it the git way directly. Yes, git is a "my way or the high way" tool, that's not great or something to emulate, but it is what it is. Trying to work around that only results in more pain. Only use the git command line, use gitk for browsing history graphically if need be, and git-gui for preparing commits. git-gui seems to be the best GUI for making commits (and is probably written in Perl with Tk). Logical conclusion from "only use the git command line": Also never make a dirty merge from your web browser.
- helloguillecl 6y agoPush and Pull almost always from the cli. But one of the things I find tools like Sourcetree useful for is selecting which changes (hunks, files or selected lines) to stage for commit, which is in my opinion much easier than with the CLI only.
- DJHenk 6y ago> selecting which changes (hunks, files or selected lines) to stage for commit I never understood why people feel the need do this. If you are working on a bug or feature, why put unrelated changes in that branch? It only creates confusion and probably messes up your tests too. And for what? It seems like a chaotic way of working to me.
- nemetroid 6y agoWho said they were unrelated? Sometimes a single commit is the best presentation of a bug fix/feature implementation, sometimes it makes more sense to split the work into multiple commits.
- lifthrasiir 6y ago> The downside with not using the merge button is that the message in the PR says “closed by [hash]” instead of “merged in…” which causes confusion to a fair amount of users who don’t realize it means that it actually means the same thing! I consider this is a (long-standing) GitHub UX flaw. This is so true, if the automatic detection of the PR merger vs. closure is hard (and I can see some reasons why) there should at least be a switch for maintainers to update the outcome message.
- berkes 6y agoDoes anyone know if there is a issue-tracker where this is reported? I'd love to +1 that. This UX-flaw is why I'm currently "forced" by my coworkers to use the buttons on GH. My git merge-scripts have some "cleanup" which I now need do manually (and thus get forgotten) for example.
- cjfd 6y agoThe ease of branching has people treat branches as if they were cookies. You cannot possibly have too many of them. But, actually, branches make refactoring more difficult. What if one person just added a parameter to a function while another person is adding new calls to that same function. The automated merge cannot fix this conflict. The KISS principle that is the corner stone of all software development would dictate that you should have the smallest number of branches possible so everyone gets the latest code as soon as possible and conflicts get minimized. For unfinished features one can have feature flags. While there are cases where one needs a feature branch I think it is best to only make feature branches if they are necessary and most development does not need to be on a feature branch. The git flow also features a development branch besides the master branch. This also seems an unneeded complication for most projects. If you have specialized testers you probably do need release branches for every release that you make but then again if you don't have specialized testers you probably don't. Here is a good talk about the harmful nature of feature branches. https://www.youtube.com/watch?v=h7LeD7VevyI https://www.youtube.com/watch?v=h7LeD7VevyI
- berbc 6y agoAs said in one of the YouTube comments for the video you linked here, it's not so much feature branches that are the problem, but long-lived feature branches. If you want to add a complex feature to a project, you could do it via several branches, one after the other. For instance, the first branch could introduce a feature flag and the second branch implement part of the new feature, and so on.
- cjfd 6y agoThis is more of a semantic quibble than anything else. Yes, long-lived branches are not just a problem but absolutely terrible. I have seen one that lived for some 4 years or so. They are a problem to the extend that they live long. The shorter they live the less of a problem they are. So, take this to its conclusion and conclude that the best feature branch is one that is only one small commit long. And now the feature branch is completely redundant....
- linuxftw 6y ago
- deleted 6y ago[deleted]
- ricardobeat 6y agoThe most important bit in my opinion: > When merging fixes and features into master, we avoid merge commits and use rebases and fast-forward as much as possible. Rebasing feature branches, and avoiding non-ff merges has been the best change I've ever made to my workflow. Makes it very easy to keep a clean, readable history that is actually useful when doing code archeology months later. Resolving conflicts is far easier than via merging too.
- jgraham 6y agoIf you have tooling to support it, rebase-and-ff-merge is perhaps an even better workflow. In this model every commit on the main branch has a first parent that's the previous merge, and a second parent that's a linear set of the commits that were landed together, with the parent of the first commit being the previous state of master. This has the following advantages: * It's clear which states master has actually been in, without having to resort to squashing each merge into a single commit. This means that you know which commits actually passed CI and are therefore good rebase targets. People often claim that when merging multiple commits each commit should individually pass CI, but that's almost impossible to achieve in practice. * Development can split single features into multiple commits for easier review and understanding later. This can be particuarly important if the changes depend on each other, but different people need to review different parts of the overall change. That's another thing that most tooling is really bad at. * The history is basically linear. The merge commits are all empty, and there is one linear history for all the states of master (the first parent of each merge commit) and one linear history for all the individual commits (the second parent of each merge commit and only parent of each non-merge commit). Of course this approach isn't well supported by mainstream tooling (e.g. GitHub) and probably requires a custom bot to do all the rebase-and-merge operations. It is pretty well supported by git itself, however.
- ufo 6y agoDoes anyone know how to make this "cactus" workflow work better on github? We use it in our organization and between us we know to always manually rebase before merging. However, when we receive an external PR from someone else it's a pain. It's also easy to accidentally forget to rebase before merging.
- boltzmannbrain 6y ago+1 "Never merge with GitHub... I don’t feel that I have the proper control"
- leegraham 6y agoMe neither, not since I got bitten by the 'Resolve Conflicts' button on the PR page also merging the PR into the target branch. Maybe it's PEBCAC, and to be fair it is documented[0], but the big red warning in the docs is missing from the page where you actually do the action. To make it more confusing there's also a disabled 'Merge pull request' button that implies that resolving the conflicts and merging the PR are separate actions 0: https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/resolving-a-merge-conflict-on-github https://docs.github.com/en/free-pro-team@latest/github/colla...
- greggman3 6y agoonly related by "git" but while I believe i'm fairly proficient in git I'm not sure how to go about explaining to an inexperienced person how to fix a merge conflict. It feels like not a simple thing to explain. As an example someone sent me a PR with 15 commits. github claims only 1 file has changed and it's a new file so no conflicts (which AFAIK is correct) but git complains that somewhere around commit 4 there's a conflict. The person sending the PR is not git comfortable, otherwise they wouldn't have this PR with 14 old unrelated commits showing up. I have no idea what state they are currently in as well. meaning, I know the state of the PR but I don't know the state of their local machine. I can clone their branch and make the merge myself but their next PR will just be the same branch they continue to work on. Explaining to them how to fix what they have and how to proceed going forward seems like it requires a very large reply. Several pages. (here's how to fix this PR, this how to fix the state of your main/master branch, here's how to make different branches, here's how to update after each PR, here's what to do if the conflicts are real, here's what to do if you haven't made any more changes to your main branch., here's what to do if you have already made changes to your main branch. I have no suggestions for solutions except to try to point them to other articles/pages/tutorials on the web
- jakeva 6y ago> git complains that somewhere around commit 4 there's a conflict. That sounds like a rebase merge, which might be the setting in the repo. A normal merge wouldn't attempt commit by commit.
- darekkay 6y agoI can relate, and I don't think there's a way around learning Git properly. Here's a quote from a post of mine: > Version control is an underrated skill. Most software engineers use it daily, and yet, many are not willing to invest more than necessary to learn it. That’s fine, but knowing more than commit/push/pull will at least make you more efficient. It will also help you solve issues you (and your colleagues) may encounter. I've had this issue a lot in the past, but mostly at work. So yes, I will spend the time to help my colleague debugging their issue. Eventually, they will get fewer issues, but the time I have to spend for their "learning by doing" would have been better invested in learning Git fundamentals. I've also had some open source contributions during Hacktoberfest, and I went with the easy way out of doing the clean-up work myself. But as you've stated, people might not learn from this, so that's not optimal.
- nocturnial 6y agoIf you want more info in your prompt, I recommend https://github.com/lyze/posh-git-sh https://github.com/lyze/posh-git-sh (bash) https://github.com/dahlbyk/posh-git https://github.com/dahlbyk/posh-git (powershell) Besides displaying which branch you're on, it also shows changed, added,... files and other useful info
- dreamcompiler 6y agoI find stashes quite useful and intuitive. For me, rebasing is the root of all evil.
- hibbelig 6y agoAs soon as two people work on the same branch, rebasing becomes a problem. As long as you're the only one modifying the branch, rebasing works nicely.
- dreamcompiler 6y agoI don't like rebase in solo code either; I want my personal history to be the truth, not some convenient fiction. In a team environment, somebody always insists on using rebase and then invariably they push a rebase to master and hijinks ensue. I wish there was a fork of git with rebase disabled.
- darekkay 6y ago> I want my personal history to be the truth, not some convenient fiction. I am mostly using the Git history when going through past changes. Why does this line do X? I just git blame this line and see exactly what happened. This is the time I really hate all those "oops, fixed mistake" and "forgot this change" commits. I don't care about those things, even if it's the "truth". They're just useless and distracting. Doing an amend/rebase/squash would have been perfectly fine in such a scenario. I have written more about rewriting Git history here [1]. > In a team environment, somebody always insists on using rebase and then invariably they push a rebase to master and hijinks ensue. I wish there was a fork of git with rebase disabled. That's why shared branches like master are usually protected, so you cannot push an alternative history. [1] https://darekkay.com/blog/git-rewriting-history/ https://darekkay.com/blog/git-rewriting-history/
- Accacin 6y agoWhere I work we always rebase on branches for features/bug fixes/tickets/whatever, but when we merge into master we always do `git merge --no-ff origin/branch`. We don't really care what the history of our branches are generally, and we preserve our commit history when we go into master. We never squash when we go into master either.
- lastofthemojito 6y ago> Ordinary days, I issue git commands several hundred times. I wonder if this is an exaggeration, or if the author truly has that git-heavy of a workload? Assuming you're working an 8-hour day, that's 480 minutes. If you're issuing "several hundred" git commands, I'd take that to mean a minimum of 300. So that's a git command every 96 seconds. When do you have the time to write the actual software in between all of those git commands?!
- freehunter 6y agoCould be some back to back commands: git add . git commit -m “update” git push Although if you’re doing it that often I’d want to set up .bashrc to condense it to a single command.
- acoard 6y agoI decided to explore this a bit. In reality, it's not that the git commands are spaced out equidistantly, it's that you have a flurry of git activity then go back to coding. So, an individual commit can easily hit 5 commands. I always do a `git status` before and after (2), plus maybe a few git adds (2), the commit (1), then potentially a push (1). That's already 6 commands for each commit. In a day I usually do approx 15 commits(±10), as well as re-bases. That's around 90 git commands just for committing. Through in a few rebases, a fetch, and an amend, and you're easily over 100. The quoted OP said "several hundred" commands. Just with commits on a pretty typical workflow, I'm at over a hundred. It doesn't surprise me that someone could double it. I often wear the hat of the "git expert" on a project, and there are some days I'm doing significantly more than just commiting and pushing code too. I have a lot of extra commands I'll run like `git log HEAD..@{u}` which shows the diff in the logs between my current branch and the upstream. And I use `git diff --cached` pretty heavily. Git blame is also invaluable when debugging. These tools don't take a way from actually writing software, they enhance it.
- grovellogic 6y agoI really like the idea deleting feature branches after they are merged, but I rather would have a recycle bin or trash can concept where the branch is deleted after ~7-30 days in case I make a mistake and delete the wrong branch. Searching for a SHA to recover a branch is never fun.
- jgilias 6y agoJust to add a datapoint. This[0] is what Linus has to say about rebasing and merging, and these[1] are the kernel development guidelines, when it comes to using git. Of course, not every project is the kernel and to each their own, but I find it's useful to know how git is used in the project for which it was originally made. [0] https://www.mail-archive.com/dri-devel@lists.sourceforge.net/msg39091.html https://www.mail-archive.com/dri-devel@lists.sourceforge.net... [1] https://www.kernel.org/doc/html/latest/maintainer/rebasing-and-merging.html https://www.kernel.org/doc/html/latest/maintainer/rebasing-a...
- bredren 6y agoI use git flow, and it took a while to get used to but I now do almost all of my git stuff in my IDE, pycharm. I used to like tabbing over to terminal to run my git commands and do my diffs. Now I use the git flow plugin and do my full process including amends, push, etc interactively. Much of it can be done by keyboard and the closeness to the auto linting and reformatting has caught many small errors, left behind little items and generally improved code quality greatly.
- khalilravanna 6y ago> Never merge with GitHub! While I agree with the spirit of this comment, in practice I do this: 1. Update: git pull --rebase 2. Clean up my commits: git rebase -i HEAD~X 3. Push: git push origin BRANCH -f 4. Merge in GitHub Works pretty well for me. That being said, I would love to be able to take care of 2 and 3 within GitHub for branches that are already updated to the parent branch.
- l0b0 6y agoI suspect OP meant `PS1='\u@\h:\w\$(brname)\$ '` rather than `PS1="\u@\h:\w\$(brname)$ "`: - double quoting the command expansion would lead to `brname` being executed once at shell startup (unless this assignment is happening in a `PROMPT_COMMAND` function or something[1]). - A literal backslash before the dollar sign gives a "#" at the end of the prompt for root. [1] https://gitlab.com/victor-engmark/tilde/-/blob/4dc4077a19250b93461521cf0830155467ec547f/.bashrc#L163 https://gitlab.com/victor-engmark/tilde/-/blob/4dc4077a19250...
- penguin_booze 6y agoHm, stgit wasn't mentioned.
- karmakaze 6y agoPossibly controversial, I like to add a "Change(s) from PR review" commit to the original set of changes of a PR then force push (with lease) amendments to that commit. That way regardless of when a reviewer last read the PR they can see changes since the original. If the changes get significant, I make a new PR and reference the old closed one.