↓ Skip to main content

Git

How to mirror Github and Bitbucket repositories

Mirroring large number of GitHub or Bitbucket repositories # Use case: I want to create local clone of a large number of repositories from an organization in GitHub / Bitbucket. Assumptions # user has SSH key registered with the GH / BB - can clone using ssh protocol user has successfully cloned at least one repo from command line before (the /etc/hosts contains host entries for BB and GH) user has modern version of Python 3 installed (3.6 or better) user has local installation of a reasonably modern Git Steps # First I use the ./bb-repo-links.sh and ./gh-repo-links.sh to generate list of repositories. See these blog articles: How to list repositories in Bitbucket and How to list repositories in github

How to list Github repositories and users

How to list repositories in GitHub # Use Case: I want to maintain repositories in an organization in GitHub. To make sure I do not miss newly added ones, I want to use API access to retrieve the list of repositories in the organization. Setup # GitHub requires a token to access the API. This token is stored in an environment variable github_token and can be generated in the user profile section - settings - developer settings.

How to list Bitbucket repositories and users

How to list repositories in Bitbucket # Use case: I want to maintain repositories in an organization in Bitbucket. To make sure I do not miss newly added ones, I want to use API access to retrieve the list of all repositories in the organization. Setup # Bitbucket requires a username and password to access the API. This information is stored in the environment variables BBUSER and BBPASSWORD. The BBPASSWORD should be an access token / app password defined in the App passwords section of the user settings:

Using SSH keys with multiple Bitbucket accounts

·296 words·2 mins
I have been using Bitbucket since 2012, long before my company moved from in-house hosted server running Gitolite and in-house instances of FishEye and Crucible to cloud based source control on Bitbucket Cloud. As legacy I was using my personal login with my gmail account as my Bitbucket identity. With merge of 3 companies in 2018 and rebranding as Pivotree, we are in process of streamlining the identity management and using SSO for identification. Time has come to split my personal identity and work identity.

Building Hugo as well on GitLab pages

·496 words·3 mins
Parallel building challenges # Unlike Github, Gitlab considers Hugo blogs first class citizens and does not impose any restrictions on repo naming. I had 3 challenges to overcome related to co-existence of GH and GL versions: I need to use same repo for both GH and GL the submodule link for public does not work on GL the site root is different - I have no custom domain forward for GitLab Using same repo # To separate the GH and GL, I have added 2 remotes to repo and special branch gitlab-pages.

Gitbits

·262 words·2 mins
Two small utilities I have places into ~/bin: git-attic # Source: https://github.com/maximeh/dotfiles/blob/master/common/.bin/git-attic #!/bin/sh # git-attic [-M] [PATH] - list deleted files of Git repositories # # Use -M to not show renamed files, and other git-log options as you like. git log --raw --no-renames --date=short --format="%h %cd" "$@" | awk '/^[0-9a-f]/ { commit=$1; date=$2 } /^:/ && $5 == "D" { print date, commit "^:" $6 }' | less Example # ➜ kubernetes-the-hard-way git:(master) ✗ git log --raw --no-renames --date=short --format="%h %cd" "$@" | awk '/^[0-9a-f]/ { commit=$1; date=$2 } /^:/ && $5 == "D" { print date, commit "^:" $6 }' 2019-11-20 374e8d9^:docs/using-rst/pdp-template-rst.rst 2019-11-17 7911114^:src/certificates/admin-csr.json 2019-11-17 7911114^:src/certificates/admin-key.pem 2019-11-17 7911114^:src/certificates/admin.csr 2019-11-17 7911114^:src/certificates/admin.pem 2019-11-17 7911114^:src/certificates/ca-config.json 2019-11-17 7911114^:src/certificates/ca-csr.json 2019-11-17 7911114^:src/certificates/ca-key.pem 2019-11-17 7911114^:src/certificates/ca.csr 2019-11-17 7911114^:src/certificates/ca.pem 2019-11-17 7911114^:src/certificates/copy-certificates-to-servers.sh git trail # I cannot remember where is this one from :-(

Storing sensitive information in Git

·1017 words·5 mins
The purpose of this is to evaluate options and suggest possible approaches for handling the sensitive information in Git repositories such as database credentials, API credentials, passwords, keys, certificates etc. Joel asked this question a few weeks ago - this is part of Milos’s security awareness program. The issue # Git repos store in cleartext all credentials, that may also be including PROD credentials.

Managing code in remote SVN repo

·546 words·3 mins
This is based on J.’s’ question in Slack: Do we have some customer where we are moving a git repo to svn in an automated fashion I just need to move the git repo into svn periodically nightly The setup (as I understand it): on client side we have a worktree that is Git repository the files needs to be copied to SVN regularly Options # Use git-svn bridge # Git client allows to “pretend” it is SVN and pull/push against remote SVN repo

Process for transferring Git repo from Gitolite to Bitbucket

·780 words·4 mins
Task # Transfer full Git history (all branches, tags, etc) to Bitbucket so that development can continue from there User setup # List all keys in Gitolite must have access to Gitolite admin interface cd $ADMIN_HOME/pensieve/PRJ-admin/gitolite-admin ➜ gitolite-admin git:(master) ll keydir total 144K -rw-r--r-- 1 miro 401 Jun 29 2015 alter.pub -rw-r--r-- 1 miro 397 Jun 29 2015 codereview.pub -rw-r--r-- 1 miro 400 Apr 18 2016 hybris.pub -rw-r--r-- 1 miro 400 Apr 19 2016 hybris2.pub -rw-r----- 1 miro 398 Mar 30 2016 irae.pub ... DELETED ... -rw-r--r-- 1 miro 401 Jun 29 2015 miro.pub -rw-r--r-- 1 miro 411 Jun 29 2015 tkuser.jenkins0.pub -rw-r--r-- 1 miro 411 Jun 29 2015 tkuser.jenkins2.pub These will be split to 5 usergroups