biviosoftware / home-env

MIT License
2 stars 2 forks source link

gmergemaster? #97

Open robnagler opened 1 year ago

robnagler commented 1 year ago

I think @e-carlin and @schellj have utilities like this, but I was curious about it. I think I'd like to add some more like this, e.g. for checking out a new branch based on the current branch (probably master). Thoughts?

#!/bin/bash
set -eou pipefail

_check_clean() {
    git update-index -q --ignore-submodules --refresh
    if ! git diff-index --quiet HEAD -- --ignore-submodules &> /dev/null; then
        _err unstaged changes
    fi
    if [[ $(git ls-files --exclude-standard --others) ]]; then
        _err untracked files
    fi
}

_err() {
    echo "$@" 1>&2
    return 1
}

_main() {
    _check_clean
    _update
}

_update() {
    declare c=$(git rev-parse --abbrev-ref HEAD)
    declare m=$(git remote show origin | perl -n -e 'm{HEAD branch: (\S+)} && print($1)')
    if [[ $c == $m ]]; then
        _err not on a branch, on "$m"
    fi
    git fetch --quiet origin "$m":"$m"
    git merge "$m"
}

_main "$@"
schellj commented 1 year ago

I generally use magit in emacs to interact with git and have been for several years. There, to update and check out a new branch based on the current branch, I would enter F u (pull upstream), then b c RET some-new-branch-name (branch, create, select base, new branch name).

Of course, adding utilities is useful as well if command line is your preference.

robnagler commented 1 year ago

Thanks.

I have played with magit (fairly recently), but didn't seem to "get it". Perhaps I need to increase my effort. I also was looking at interactions with github issues, which are more complicated. (I created a mapping of issues to org-mode and back in python, which is nice enough, but it wasn't really effective for project management in the end. Now I just use simply copy and paste into org mode for my own issues.)

This doesn't solve the problem for other people, but maybe that's not a problem.

e-carlin commented 1 year ago

This is interesting. I don't have anything like it. You can see my git stuff by searching for git in here (it's messy...).

The script looks good although it would need to be tweaked for my workflow. I usually keep many untracked files around while I'm working as a reminder to clean them up when I'm done (ex data files). I also avoid merge when possible. On working branches I always do rebase (I like the linear commit history). Sometimes if there are a lot of conflicts I'll resort back to merge which makes reconciling the conflicts easier.

I've also tried magit (and gitLens in vscode) but went back to the command line. I haven't had an "aha" moment using any of the tools to make learning them worth it. The one tool I do use frequently is vc-region-history in emacs. A good tool for searching the git log and for doing diffs would be useful.

schellj commented 1 year ago

I also prefer rebasing when possible.

I think the main value-add of magit for me is selecting and staging individual lines from all of the unstaged changes. I like to group changes into logical units and I find doing that is much easier than from the command line.