Posts tagged: git
All posts with the tag "git"
--name-status is a great way to see what files have changed in a git diff alongside the status code. I recently used this in a script to create a report of new and modified files during a build.
The tea command for gitea (used by forgejo) has a flag for login. With gitea you can have multiple accounts logged in. When you try to run a command such as repo create it will prompt you which login to use, but I learned that you can bake it in to all of them with --login <login-name>
It’s so easy to forget low level tech sometimes. Things that are dead simple and just work without a hitch. git is one of those rock solid things thats very easy to remember all that it does, this is a classic use case.
This just works
cd /parent/directory/for/repo git clone ssh://username@server/path/to/repo
In order to recieve you must update the remote to allow recieve.
git config receive.denyCurrentBranch updateInstead
Now you can pull update push.
...
This site gives us a glimpse into the development workflow using git over email, without remote centralized servers. I found it interesting how patches can be sent with an optional cover letter nearly like a pr would be made.
Forgejo supports repository mirrors, I think this is how I am going to handle migrating all of my github repos into forgejo. over time I’ll probably go through and delete a bunch of unnecessary one from github, ones that might have a user or two I might keep on github. I have such small scale projects with almost no users I am not sure that It really matters for me or not.
This post is a masterclass in blogging, cross linking, backing up your ideas with posts from other great sources. I have a week of reading inside this post, and need to come back later when Im not sick.
Damn Prime covers this so well from all angles. Can’t overstate the importance of that last step. Look at the issues, and raise an issue if there is not one before putting in a bunch of hard work. Make sure that the maintainers are open for your changes and no one else is already working on it.
great poll of git questions
poll: did you know that in a git merge conflict, the order of the code is different when you do a merge/rebase?
merge:
OTHER BRANCH’S CODE
...
Recently I added two new bash/zsh aliases to make my git experience just a tad better.
Most of our work repos were recently migrated to new remote urls, we scriped out the update to all of the repos, but I was left with a tracking error for all of my open branches. To easily resolve this I just made an alias so that I can just run trackme anytime I see this error.
There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details git pull <remote> <branch> If you wish to set tracking information for this branch you can do so with: git branch --set-upstream develop origin/<branch>
getting the branch #
The following command will always return the currently checked out branch name.
git symbolic-ref --short HEAD
Injecting this into the suggested...
...
I love getting faster in my workflow, something I have recently added in is creating GitHub repos with the cli. I often create little examples of projects, but they just end up on my machine and not anywhere that someone else can see, mostly because it takes more effort to go create a repo. TIL you can create a repo right from the command line and push to it immediately.
gh repo create waylonwalker-cli
want to see what this repo I created is about? #
Check out what I created here.
Sometimes you have a pretty old branch you are trying to merge into and you are absolutely sure what you have is what you want, and therefore you don’t want to deal with any sort of merge conflicts, you would rather just tell git to use my version and move on.
The first step is to make sure your local copy of the branch you are moving into is up to date.
git checkout main git pull
update your feature branch #
It’s also worth updating your feature branch before doing the merge. Maybe you have teammates that have updated the repo, or you popped in a quick change from the web ui. It’s simple and worth checking.
git checkout my-feature git pull
start the merge #
Merge the changes from main into my-feature branch.
...
I am getting ready to do some timeseries analysis on a git repo with python, my first step is to figure out a way to list all of the git commits so that I can analyze each one however I want. The GitPython library made this almost trivial once I realized how.
from git import Repo repo = Repo('.') commits = repo.iter_commits()
This returns a generator, if you are iterating over them this is likely what you want.
commits # <generator object Commit._iter_from_process_or_stream at 0x7f3307584510>
The generator will return git.Commit objects with lots of information about each commit such as hexsha, author, commited_datetime, gpgsig, and message.
I was editing some blog posts over ssh, when I ran into this error. gpg was failing to sign my commits. I realized that this was because I could not answer to the desktop keyring over ssh, but had no idea how to fix it.
This is the error message I was seeing.
gpg failed to sign the data ssh
The fix #
The fix ended up being pretty simple, but quite a ways down this stack overflow post. This environment variable tells gpg that we are not logged into a desktop and it does not try to use the desktop keyring, and asks to unlog the gpgkey right in the terminal.
export GPG_TTY=$(tty)
The log in menu #
This is what it looks like when it asks for the passphrase.
...
Sometimes you get a PR on a project, but cannot review it without wrecking your current working setup. This might be because it needs to be compiled, or a new set of requirements. Git worktrees is a great way to chekout the remote branch in a completely separate directory to avoid changing any files in your current project.
# pattern # git worktree add -b <branch-name> <PATH> <remote>/<branch-name> git worktree add -b fix-aws-service-cnsn /tmp/project origin/fix-aws-service-cnsn
This will create a new directory /tmp/project that you can review the branch fix-aws-service-cnsn from the remote origin. If you have setup different remotes locally you can check for the name of it with git remote -v
GitPython is a python api for your git repos, it can be quite handy when you need to work with git from python.
I recently made myself a handy tool for making screenshots in python and it need to do a git commit and push from within the script. For this I reached for GitPython.
How I Quickly Capture Screenshots directly into My Blog
GitPython is a python library hosted on pypi that we will want to install into our virtual environments using...
...
Setting up your git pager to your liking can help you navigate diffs and logs much more efficiently. You can set it to whatever pager you like so that your keys feel nice and smooth and your fingers know exactly what to do. You might even gain a few extra features.
You can set the pager right from your command line with the following command.
git config --global core.pager 'more'
You can also set your pager by editing your global .gitconfig file which by default is set to ~/.gitconfig.
[core] pager = more
Color #
In my experience you need to turn colors off with nvim. bat handles them and looks good either way, but nvim will be plain white and display the color codes as plain text if color is on.
...
If you have ever mistyped a git command very close to an existing one you have likely seen this message.
❯ git chekout dev git: 'chekout' is not a git command. See 'git --help'. The most similar command is checkout
Automatically run the right one #
What you might not have known is that you can configure git to just run this command for you.
# Gives you 0.1 seconds to respond git config --global help.autocorrect 1 # Gives you 1 seconds to respond git config --global help.autocorrect 10 # Gives you 5 seconds to respond git config --global help.autocorrect 50
Fat Fingers Gone #
Now when you typo a git command it will autmatically run after the configured number of tenths of a second.
...
So worktrees, I always thought they were a big scary things. Turns out they are much simpler than I thought.
no special setup
I thought you had to be all in or worktrees or normal git, but not both. When I see folks go all in on worktrees they start with a bare repo, while its true this is the way you go all in, its not true that this is required.
Making a worktree is as easy as making a branch. It’s actually just a branch that lives in another place in your filesystem.
...
Has no upstream branch errors in git can be such a damn productivity killer. You gotta stop your flow and swap over the branch, there is a config so that you don’t have to do this.
If you have not yet configured git to always push to the current branch, you will get a has no upstream branch error if you don’t explicitly set it.
Let’s show an example
git checkout -b feat/ingest-inventory-data git add conf/base/catalog.yml git commit -m "feat: ingest inventory data from abc-db" git push
You will be presented with the following error.
...