Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

2021-09-02

Remove Secrets from git Repository

Sometimes you accidentally create a commit and push a sensitive data to the git server, here's how you can remove the secrets from the git repo using https://rtyley.github.io/bfg-repo-cleaner/
  1. clone a repo you want to clean, change directory to newly cloned folder
  2. create a file containing all the lines/secrets you want to remove 
  3. run  java -jar ~/Downloads/bfg-1.14.0.jar --replace-text /tmp/.env .
  4. run git reflog expire --expire=now --all && git gc --prune=now --aggressive 
  5. foreach branch that contains the changes, do git checkout branchName && git push --force
After force push, the offending lines will be replaced with "***REMOVED***" line.

2020-10-16

Cleanup git and docker Disk Usage

Sometimes our cloned repository became so freakin large, for example golang's google.golang.org/api, currently mine consume about 1.1GB. We could compress it using garbage collection parameter:

git gc 
du -hs .
# 664 MB in about 20 seconds

Or if you have time you can use aggresive GC, like this:

git gc --aggressive
du -hs .
# 217 MB in about 5 minutes  

Or if you do not need any old history, you can clone then replace, like this:

git clone --mirror --depth=5  file://$PWD ../temp
rm -rf .git/objects
mv ../temp/{shallow,objects} .git
rm -rf ../temp
# 150 MB in about 2 seconds

Next you can reclaim space from docker using this command:

sudo docker system prune -a -f
docker system df

For more disk usage analysis you can use baobab for linux or windirstat on windows.

2018-07-01

Introduction to gitflow

GitFlow is one way to manage git repository, where master branch forked into develop branch, and each person will create their own branch when they develop a feature, merged back to develop branch. See this video for the detailed explanation. Also this cheatsheet for the comparison between git-flow command and normal git command.

When you are using Gitflow without git-flow program, you will have to type this long git commands:


Or you can use Git GUIs.

2016-11-25

How to become AUR package adopter?

AUR is ArchLinux User Repository, similar to Ubuntu's Launchpad.
To adopt an orphaned package it's easier than you think! adopt now :3


What you need to do is register, find an orphaned package, then click on the "Adopt Package" link.


Don't forget to set your public key on your "My Account" menu.


After that you can clone the repository, see "Git Clone URL" on the first line of the package, edit and reupload:

git clone ssh://aur@aur.archlinux.org/bla.git
# do some changes on PKGBUILD
git add .
git commit -m 'updated bla package to version X'
git push origin master

Done :3 you have successfully adopt and maintain a package :3

2014-08-11

How to make git ignore changes on commited files?

Sometimes there are some file that we want to ignore some file on git, of course we could use .gitignore, but that only take effect on untracked files. When the files already tracked/commited, we could make that file changes ignored using git update-index command, for example:

git update-index --assume-unchanged file-to-be-ignored

From now on, that file would not appear on git status or git diff when changed. When you want to track back the changes, use --no-assume-unchanged flag.

What to do when git pull conflict before commit?

Sometimes we want to pull from git without committing current changes, and yes, the correct way is to commit our changes first before pulling, so we could merge the conflict. But if you doesn't want to do that, there are some trick that you could use, that is git stash, the usage example:

# to store all changes on the stash
git stash
# this should no longer conflict
git pull
# to overwrite from previous stash
git stash pop
# you could see the difference using
git diff