![]() |
VOOZH | about |
In software development, mastering advanced tools and techniques is important for efficiency and collaboration. Git, GitHub, GitLab, and Bitbucket offer features beyond basic version control, like rebasing, cherry-picking, stashing, submodules, and Git hooks in Git, as well as GitHub Actions, GitLab CI/CD pipelines, and Bitbucket Pipelines.
This article will explore these advanced functionalities to help developers improve productivity and code quality.
Table of Content
Rebasing is the process of moving or combining a sequence of commits to a new base commit. By default, a rebase will simply drop merge commits from the todo list, and put the rebased commits into a single, linear branch.
Syntax:
git checkout <feature-branch>
git rebase main
Cherry-picking allows you to apply changes introduced by some existing commits.
Syntax:
git cherry-pick <commit-hash>Stashing is useful when you want to save your work temporarily without committing it.
git stashgit stash listThis will give an output that looks something like this
stash@{0}: WIP on my-branch: ca96af0 Commit message 3
stash@{1}: WIP on my-branch: 03af20c Commit message 2
stash@{2}: WIP on my-branch: 216b662 Commit message 1
git popgit pop stash@{2}Submodules allow you to keep a Git repository as a subdirectory of another Git repository.
Syntax:
git submodule add <repository-url>.gitmodules: In this file we have to define:
[submodule “app/styles/core”]
path = app/styles/core
url = ../../repo/core.git
branch = master
Git hooks are scripts that run automatically every time a particular event occurs in a Git repository. They let you customize Git’s internal behavior and trigger customizable actions at key points in the development life cycle.
Hooks reside in the .git/hooks directory of every Git repository. Git automatically populates this directory with example scripts when you initialize a repository. If you take a look inside .git/hooks, you’ll find the following files:
applypatch-msg.sample pre-push.sample
commit-msg.sample pre-rebase.sample
post-update.sample prepare-commit-msg.sample
pre-applypatch.sample update.sample
pre-commit.sample
To install a hook, all you have to do is remove the .sample extension.
As an example, try installing a simple prepare-commit-msg hook. Remove the .sample extension from this script, and add the following to the file:
#!/bin/sh
echo "# Please include a useful commit message!" > $1
Hooks need to be executable, so you may need to change the file permissions of the script if you’re creating it from scratch. For example, to make sure that prepare-commit-msg executable, you would run the following command:
chmod +x prepare-commit-msgThis has an important impact when configuring hooks for a team of developers. First, you need to find a way to make sure hooks stay up-to-date amongst your team members. Second, you can’t force developers to create commits that look a certain way—you can only encourage them to do so.
GitHub Actions enable you to automate workflows directly in your GitHub repository by using CI/CD, automated testing etc.
Setting up workflows:
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run a one-line script
run: echo Hello, world!
GitHub Packages provides hosting for software packages, making it easy to distribute them.
GitHub Discussions provides a space for conversations about your project.
GitHub offers robust project management tools.
GitLab is a complete DevOps platform, delivered as a single application.
GitLab CI/CD enables you to automatically build, test, and deploy your code.
stages:
- build
- test
- deploy
build:
stage: build
script:
- echo "Building..."
test:
stage: test
script:
- echo "Testing..."
deploy:
stage: deploy
script:
- echo "Deploying..."
GitLab Runner is an application that works with GitLab CI/CD to run jobs in a pipeline.
sudo gitlab-runner registerGitLab offers robust security features.
Bitbucket, part of the Atlassian suite, integrates seamlessly with Jira.
Bitbucket Pipelines offers integrated CI/CD.
Setting up pipelines: Define in bitbucket-pipelines.yml.
pipelines:
default:
- step:
name: Build and Test
script:
- echo "Building and testing..."
Bitbucket offers strong code review features.
Bitbucket provides essential security features.