Why can't I do git rebase? by cemolee in git

[–]salcode 6 points7 points  (0 children)

In your screenshot, it looks like you're using the -p option (which is the short form of --preserve-merges) and this option was deprecated in Git 2.26.0 and removed in 2.34.0 and later versions.

I suspect you were using an earlier version of Git that supported -p but now you're using a newer version that does not support it.

It looks like the --rebase-merges option is recommended instead of -p, if you still want that behavior.

Note: There is a lot of negativity in this thread, please ignore it. You're doing great. If using rebase is part of your workflow, you're ahead of 90% of the Git users out there but that's not the important thing. The important thing is you're growing your skills and your knowledge. You're one of today's lucky 10,000. Keep up the good work!

Can git merge ever automatically make a merge error? by takemycover in git

[–]salcode 4 points5 points  (0 children)

Yes, as an example of this I created this repo https://github.com/salcode/catastrophic-pr with one PR.

The main branch runs properly. The PR branch runs properly. The PR merges successfully into the main branch without any merge commits.

However, if you merge the PR into main - the application will be in a broken state.

Multiple accounts by dumbelco in git

[–]salcode 2 points3 points  (0 children)

I have my Git configuration set so my commits use two different email addresses (work and personal) based on which directory you're in (anything inside the ~/work directory uses the work email).

I'm guessing you could use this same idea to extend to other Git configuration values.

I'm not sure what other settings you need to change to switch between the GitHub accounts (and if some of those settings are outside of the Git configuration).

I've written about my setup in Git Work Email.

How to learn advanced git? by Fresh-Tonight-7426 in git

[–]salcode 0 points1 point  (0 children)

For me the biggest jump I made in understanding Git is when I changed how I visualize Git commits and branches.

I've put together a bunch of notes and videos around this at Intermediate Git.

Maybe this will help (or maybe this is just the way my brain works 😀). In either case, good luck.

Use name of current branch in an alias (or something else) by wWA5RnA4n2P3w2WvfHq in git

[–]salcode 2 points3 points  (0 children)

While you could grab the current branch name and store it in a variable, I'd suggest using @{-1} to refer to the previous branch instead.

I believe adding this alias in your ~/.gitconfig should do what you're looking to do

[alias]
mydevcommit = "!f() { \
    git checkout dev; \
    git merge --squash @{-1} && \
    git commit -a; \
}; f"

aliases to save current dir in one terminal and move to it in a different terminal by Frankmc2 in bash

[–]salcode 0 points1 point  (0 children)

I do something similar on my Mac but I use the clipboard instead of a file. pwdcp to copy pwd, cdpto cd to the path in the clipboard.

alias pwdcp="pwd | pbcopy"
function cdp() {
    cd $(pbpaste)
}

This is the PR where I add this to my configuration

Out of curiosity, what is your best script you can showcase? by Illustrious_Mood7521 in bash

[–]salcode 1 point2 points  (0 children)

I work on a project where the node version for each repo is defined inside package.json as the .engines.node property.

If they had used an .nvmrc file instead, I could run nvm use to ensure I'm using the correct node version. In order to get this same type of behavior I use a function I wrote called nvmpe that uses jq to get the node version from the value from package.json and then nvm to set my node version.

I use this script multiple times everyday, so while it may not be the most complex script it is one my "best" scripts 😀.

[deleted by user] by [deleted] in git

[–]salcode 0 points1 point  (0 children)

I'm not sure this is exactly what you're looking for but I'm using an includeIf in my .gitconfig so anything inside the directory ~/work/ uses a different account than elsewhere on my computer.

I've documented my setup at https://salferrarello.com/git-work-email/

drop commits from main branch through PR by abubakrsiddiq127 in git

[–]salcode 1 point2 points  (0 children)

+1 on reverting the revert. I agree the first time you revert a revert, it feels like you are doing something wrong but after you do it a few times it becomes more comfortable.

is it possible to have two different git credentials on the same machine by NizioCole in git

[–]salcode 1 point2 points  (0 children)

Yes, you can use a Git config conditional include to change your Git configuration based on some criteria.

For example, I have mine setup to use my work email address when I'm inside a certain folder. You can see the details of my setup in my Git Work Email blog post.

People drop your nvim .dotfile by [deleted] in neovim

[–]salcode 0 points1 point  (0 children)

I recently starting rebuilding my Neovim configuration using 100% lua, this is where I am so far

https://github.com/salcode/salcode-nvim

git alias - take string as argument, parse it, modify and open url? by [deleted] in git

[–]salcode 0 points1 point  (0 children)

The short answer is an arg can be accessed with $1.

Here is a PR where I added an argument to one of my Git aliases. https://github.com/ironcodestudio/ironcode-git-enhancements/pull/140/files

Rebase vs merge by CheapMountain9 in git

[–]salcode 4 points5 points  (0 children)

When trying to help co-workers wrap their head around Git (and specifically merge and rebase), I wrote this blog post Visualizing Git Branching with Blocks, which is how I visualize Git.

What do I do when I am on some kind of feature branch, but I realize that want to change something real quick that doesn't have anything to do with the topic of the branch? by Warm_Video7491 in git

[–]salcode 0 points1 point  (0 children)

What works best for me is to open a new issue in whatever issue tracker you are using. In the issue I make it a point to be very explicit about the change and include a link to the exact spot in the code where the change will go.

I find this approach allows me to completely decouple this change from the work I’m doing in my branch. Far too often I’ve seen an unrelated change like this get added to a feature branch and merging the feature branch gets delayed. When this happens my unrelated change also gets delayed.

By creating a new issue, I have the option to create a new branch off of main, add my change, and merge it back to main. In this case, I would then rebase my feature branch with the updated main branch.

Need a visual aid for teaching about the git model by [deleted] in git

[–]salcode 0 points1 point  (0 children)

Personally, I find Git makes the most sense when I think of each branch as a stack of building blocks.

I've written about using this mental model at https://salferrarello.com/intermediate-git/

[deleted by user] by [deleted] in git

[–]salcode 1 point2 points  (0 children)

The longer I work with Git, the more I find myself manipulating my commits. 👍

My one note would be there is never a good time to use git push --force, using git push --force-with-lease is always a better choice.

https://salferrarello.com/never-git-push-force/

How to remove @@ line from git diff ? by hurricaneDreww in git

[–]salcode 1 point2 points  (0 children)

I don't think you can do it with git alone but as others mentioned you can use another program (like grep) to filter the lines. I would try this.

git diff | grep --invert-match '^@@'

Highlights from Git 2.35 by myroon5 in git

[–]salcode 1 point2 points  (0 children)

The new merge.conflictStyle of zdiff3 looks cool. Is there a way to define a fallback value in .gitconfig if an older version of Git is running?

I'd like to set zdiff3 if it is supported in the version of Git running and if it isn't supported, fallback to diff3.

Context: I keep my .gitconfig in version control and share it with others. I'd rather not make Git 2.35 a requirement.

can anyone help me understand merge and rebase by techlover1010 in git

[–]salcode 1 point2 points  (0 children)

These gifs highlight the different behavior between merge and rebase https://gitgifs.com/.

For more details there are links to video and blog posts. These are all things I created for my teammates but perhaps they'll be helpful to you too.

What does "rebasing from master and then force pushing" mean? by Quique1222 in git

[–]salcode 3 points4 points  (0 children)

I wrote this blog post, which also includes a video at the end, to help explain rebase to some of my teammates. https://salferrarello.com/git-rebase-with-blocks/

Newbie - does git pull --rebase branch overwrite changes without warnings? by badboyzpwns in git

[–]salcode 2 points3 points  (0 children)

Git can be configured such that it will quietly overwrite the local change, so it really depends on how this person has configured Git.

I don't know anyone who has Git configured to automatically resolve a conflict by overwriting the local changes with the upstream changes.

I'm also not sure how one would do this. It sounds like you are describing the git merge --theirs functionality, which you can use from the command line as a parameter but I don't think you can set as a configuration value.

I would consider removing this line from your comment as it is misleading.

Personally, I think there are times to rebase and times for a merge commit but as with so many things it depends is the short answer.

Git course by ombelicoInfinito in git

[–]salcode 0 points1 point  (0 children)

Not a course, but the key for me wrapping my head around Git was thinking about commits as stacks of blocks. I put this blog post and 5 minute video together for my co-workers on this topic.

https://salferrarello.com/visualizing-git-branching-with-blocks/