How to get default Git branch?

I found a way to detect the default-branch if it is not master. git remote show [your_remote] | sed -n ‘/HEAD branch/s/.*: //p’ I tested it with multiple repo from gitlab, and it worked fine. (for the most situations [your_remote] will be origin, run git remote to check the name of your remote)

How can I delete a remote tag?

You can push an ’empty’ reference to the remote tag name: git push origin :tagname Or, more expressively, use the –delete option (or -d if your git version is older than 1.8.0): git push –delete origin tagname Note that git has tag namespace and branch namespace so you may use the same name for a … Read more

Why does git sign with GPG keys rather than using SSH keys?

Update Sept. 2022: 1Password supports generating and storing an SSH key for Git commit signature, recognized by GitHub. Update 2021: OpenSSH 8.2+ is available (packaged for instance in Git For Windows 2.33.1), and “it is now possible to sign arbitrary data with your SSH keys” (Andrew Ayer), including commits in Git. Andrew points to git/git … Read more

What does ‘adding to the index’ really mean in Git?

A useful metaphor “Adding a file to the index”, “staging a file”, “adding a file to the staging area” are all synonymous. I personally prefer the term staging area to index because it lends itself to a useful metaphor. If committing is akin to “taking a snapshot”, staging is about “composing the shot“. Imagine yourself … Read more

Deploying GitLab pages for different branches

I’ve had success using the browsable artifacts for this purpose. In your example, you would create a job for your develop branch and set the PUBLIC_URL to the path on where the job’s artifacts are published: develop: artifacts: paths: – public environment: name: Develop url: “https://$$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/index.html” script: | # whatever stage: deploy variables: PUBLIC_URL: … Read more

How do I react to new tags in git hooks?

Tags are refs like any other (like commit). If tags are pushed to a repo with a post-receive hook, that hook will be called and will list all updated refs, that is both old and new values of all the refs in addition to their names (on its standard input). See this server post-receive email … Read more

git merge, keep both

There is no ‘merge strategy’ for resolving these conflicts. However, if you truly want a conflict like: <<<< ours Foo ========= Bar >>>> theirs to resolve to Foo Bar then you can configure the ‘merge driver’. From the gitattributes man page: union Run 3-way file level merge for text files, but take lines from both … Read more