Skip to main content
16 votes
Accepted

Git delete all merged in local branches

Improve your file handling: Don't use a hard coded file name for temporary files. Don't spew temporary files into the current directory. Make sure you clean up temporary files even on error. The first ...
jpmc26's user avatar
  • 1,243
14 votes

Git delete all merged in local branches

DRY - don't repeat yourself "Don't repeat yourself" is a popular programming principle. You could apply it here by not repeating your filename over and over. ...
chicks's user avatar
  • 2,889
14 votes

Git Push Bash script

Rather than make it interactive read -p "Continue? " yn I would make this more like other command line tools. You have default values and allow ...
Loki Astari's user avatar
  • 97.7k
7 votes

Git delete all merged in local branches

I am assuming you are starting nano so that you may remove possible occurrences of master branch (or some other static branch) ...
hjpotter92's user avatar
  • 8,921
7 votes
Accepted

A Python script that generates git commits for the last year

Python is actually well-known for having a unified style-guide. It is called PEP8. It has both general advice as well as specific advice (naming and such). flake8 ...
Graipher's user avatar
  • 41.7k
7 votes

Git Push Bash script

If you're going to keep your script interactive, I'd reorder these lines: git add . read -r -p "Commit name/number/identifier: " NUM to ...
Ifthel's user avatar
  • 149
7 votes

Git Push Bash script

Do you really expect the user to type in REMOTE and BRANCH, copying the output of the previous commands? What if the user makes a typo? Why bothering the user at all? Instead of ...
Guntram Blohm's user avatar
5 votes
Accepted

Measure size of repository as a function of time

This is good, useful, powerful. Let's make it better! There's no need for os here, so remove it. os.curdir can just be ...
Reinderien's user avatar
  • 71.1k
5 votes
Accepted

Tracking 1400+ client codes, multi-threading nightmare

First, I'm pretty sure that it's impossible for os.chdir(path) to meaningfully apply different working directories per thread; and even if it were possible it ...
Reinderien's user avatar
  • 71.1k
5 votes

Git Push Bash script

Add a default in your case, take into account that the user could press any key besides y an n. – schrodingerscatcuriosity, CC BY-SA 4.0, 2022-06-24 22:18:07
4 votes
Accepted

Git pie - Perl oneliner for Git

As written, $new will contain the return value of s///, which is 1 (true) or the empty string (false). This will (almost) never ...
Oh My Goodness's user avatar
4 votes

Git Insert Delete Graph

Overview It is great that you: Used strict and warnings Leveraged other people's code by using the CPAN modules Used comments ...
toolic's user avatar
  • 15.7k
4 votes
Accepted

automating to push changes to github for multiple repos using python

Review Stick to the PEP8 style guide Functions and variables should be snake_case Constants like gitUrl should be ...
Ludisposed's user avatar
  • 11.8k
4 votes
Accepted

Bash/zsh function that cd to the root of git tree

Great 100% pass on shellcheck which means you're doing great with quoting everything that could be potentially problematic. scoping variables using [[ conditional ...
chicks's user avatar
  • 2,889
4 votes
Accepted

How to reduce the build time of Docker image layer in GitHub Actions?

COPY ZscalerRootCertificate-2048-SHA256.crt /usr/local/share/ca-certificates/ZscalerRootCertificate-2048-SHA256.crt The command here runs, presumably, on a file. ...
Peilonrayz's user avatar
  • 44.5k
3 votes
Accepted

Counting times a file was committed to Git

I was going to say that this shouldn't be done in C#, but then after some thought last night, I came up with a really dirty idea. You're basically trying to get the count of things that happened with ...
Der Kommissar's user avatar
3 votes
Accepted

GitHub repo tree generator

@Reinderien's answer makes a very good point about docstrings and using those to describe your code: it would be much easier to understand if I knew what the various components are generally intended ...
Graham's user avatar
  • 1,419
3 votes

GitHub repo tree generator

I see nothing wrong with the code itself, but you're in dire need of docstrings. Arcane functional one-liners like the one in intersperse are impenetrable unless ...
Reinderien's user avatar
  • 71.1k
3 votes

Git delete all merged in local branches

I've actually written a script to do the same thing myself. My tips: Advice I wouldn't use git branch, its output is only meant to be human readable (in git ...
onlynone's user avatar
  • 131
3 votes

Daily Add/Del Git Log Analysis

I would apply the following improvements: use collections.defaultdict to count down the number of added and deleted lines separately. This would help to improve the ...
alecxe's user avatar
  • 17.5k
3 votes

Bash: change git remote from SSH to HTTPS within a given dir

Extracting remote urls Parsing the config file is error-prone. A much better way to extract the information about remotes is using Git commands. This will simplify your script a great deal. ...
janos's user avatar
  • 113k
3 votes

Safely pruning merged topic branches locally

Previous exit code This will only ever print 0 exit code: if [[ ${1} ]]; then echo "The previous command exited with ${?}"; fi Because the last exit code at the ...
janos's user avatar
  • 113k
3 votes
Accepted

Safely pruning merged topic branches locally

The final line has no effect: trap error SIGHUP SIGINT SIGTERM As the program is about to exit, we're exceedingly unlikely to receive any of those signals ...
Toby Speight's user avatar
  • 88.3k
3 votes

bash wrapper around 'git commit' to automatically bump (Python) package CalVer and create matching CalVer tag on new commit

First of all I'd like to recommend shellcheck (online, GitHub) as a very useful tool to detect errors (even small misspellings of variables) and possible misbehaviours, etc.. With this you would have ...
Martin - マーチン's user avatar
3 votes
Accepted

Syncing GitHub repositories local, remote and forks

There's no need to reinstate the initial value of IFS because there's nowhere for the new value to propogate. When your script exits, the new value just ceases to ...
Oh My Goodness's user avatar
3 votes
Accepted

Display git commit statistics in bash

Some suggestions: shellcheck should give you a few suggestions. I won't mention things I expect it to find. Uppercase names are by convention only used for exported ...
l0b0's user avatar
  • 9,117
3 votes
Accepted

Pre-commit hook to prevent large file commits

Although described as a Bash script, this appears to be a portable shell script that can be run by any POSIX-conformant shell. That's a good thing, as it means we can use a much smaller, leaner shell ...
Toby Speight's user avatar
  • 88.3k
3 votes

How to manipulate directories using Python

Enumerate counter = 1 for repo in git_repo_tags: # ... print('--Removing the .git folder ' + str(counter) + '/8') counter += 1 should be using ...
Reinderien's user avatar
  • 71.1k
3 votes

Fast git change sets with git wrapping scripts

Addressing your main concerns In general, maybe there is something I am missing therefore fixing details is waste of time [...] Actually I'm wondering if there's something that I am missing about ...
janos's user avatar
  • 113k
3 votes

How to reduce the build time of Docker image layer in GitHub Actions?

We have two goals for a speedy build of a docker image: small image small diffs I notice you're not yet using layers. You want to. You start out with LTS Jammy Jellyfish as the ...
J_H's user avatar
  • 42.1k

Only top scored, non community-wiki answers of a minimum length are eligible