How to sync Github to Gitlab

How to sync Github to Gitlab

I, like a lot of people who have used Git, started out using Github. But I became a bit frustrated by the lack of some features that Gitlab had, but Github didn’t (unlike many, the decision to switch to Gitlab wasn’t because of Microsoft’s takeover of Github).

How to sync Github to Gitlab

I, like a lot of people who have used Git, started out using Github. But I became a bit frustrated by the lack of some features that Gitlab had, but Github didn’t (unlike many, the decision to switch to Gitlab wasn’t because of Microsoft’s takeover of Github).

However, very few online code editors worked with Gitlab, while many would work with Github. While it isn’t a big hassle, time spent doing manual tasks (i.e. uploading and downloading files) adds up. Although Gitlab has a web IDE, I prefer using a dark mode and it doesn’t have the functionality that some other IDEs (Codeanywhere and Gitpod, for example) have.

To solve this, I decided to sync my Github repositories to Gitlab. If I make a change on Github, it will be reflected on the Gitlab project.

Photo by Pankaj Patel on Unsplash

What you’re going to want to do is to sign up for Github, if you haven’t already. Create a repository on Github, or choose the one that you want to sync to Gitlab.

If you haven’t signed up for Gitlab, sign up now, choosing the “sign up with Github option”. If you’ve already signed up for Gitlab, go to your settings and find the button that says “connect to github”.

All the services that can be connected to Gitlab

Once you’ve connected your github and gitlab accounts, click the little + button to the left of the search bar. Click “new project”.

The new project area

You are then going to want to click on the tab that says “CI/CD for external repo”. Click “Connect repositories from Github.” Select your project (it can be a personal repo or a corporation repo). It will take a few minutes to sync, and then you’re done!

Please note that while changes on the github repo will be reflected on gitlab, if you change something on gitlab, it won’t be reflected on Github.

Enjoy!

— Limo

Do you have this Github Repository in your Github Account?

If you are a developer, you must have this github repository in your account.

How to be more productive on GitHub

With the recent announcement by GitHub of&nbsp;<a href="https://blog.github.com/2019-01-07-new-year-new-github" target="_blank">unlimited private repositories</a>, let’s take a few minutes before we push our code we don’t want anyone else to see to the cloud, and make sure we’re making the most of what GitHub has to offer.

With the recent announcement by GitHub of unlimited private repositories, let’s take a few minutes before we push our code we don’t want anyone else to see to the cloud, and make sure we’re making the most of what GitHub has to offer.

GitHub is built with some extremely helpful shortcuts and productivity-boosting features. From personal experience, however, it’s clear that these often fall under the radar amongst developers.

If I’ve ever witnessed a specific GitHub feature surprise or assist someone, it’s on this page. That said, what follows is by no means an exhaustive list.

Quick fuzzy file search in repositories

This is, without doubt, the fastest way to browse a repository when you know what you’re looking for. Open up any repository and press t. You can now search for the name of any file in the repository, and use the arrow keys on your keyboard to move through the results. Press Enter to open the file.

Code change suggestions in pull requests

When commenting on a piece of code in a pull request, you can suggest alternative code using the “Suggested Changes” feature. The author of the pull request will be able to apply your suggestion instantly without leaving GitHub. To make the suggestion, surround a code snippet with a multi-line Markdown snippet and add the tag “suggestion”:

Now that you’ve made the suggestion, the author of the pull request can immediately apply it to their branch, without the hassle of manually changing the file!

Navigate the code tree like in an IDE

This one requires an unofficial Chrome extension, but it’s a slightly more familiar way to navigate your code, compared to the default interface. The Octotree extension lets you browse GitHub repositories with a sidebar tree view similar to what you get in applications like VS Code.

Jump to a function when reviewing code

Unless you’re reviewing a single function, a code review often involves a lot of jumping between function calls and their definitions (and therefore a lot of scrolling up and down). GitHub lets you jump to a symbol by pressing twhen you’re looking at files in a pull request.

Creating a permalink to a file

When viewing a file or directory, press y, and the URL will be converted to a permalink, which you can share safely in the knowledge that the contents of the file will never change.


If you send a link to a file or directory on GitHub without making it into a permalink, you’ll need to accept the possibility that the file could disappear tomorrow, breaking the link!

Viewing the blame and change recency heatmap

When viewing a file, you can press b to view the Git blame and a heatmap showing how recently each line was changed. It’ll tell you who most recently changed each line of code, and give you a clickable link taking you to the full commit the change was part of.


On the right-hand side of the gutter (which contains the commit message and author), you’ll notice an orange vertical bar. The more vivid this bar is, the more recent the change, meaning you can easily scan the file to find the freshest code!

Powerful code search

GitHub indexes most code and offers powerful search functionality over it. If you need to find something in a repository, but don’t plan on making any changes to it. There’s usually no need to check the repository out. Press /to search all the code in the repository.

If your search contains multiple words and you want to search for occurrences of your specific search query, put the quotations around the query. You can filter your searches by other things too, such as file size, extension, the path the file is on, and much more.

Saved replies

If you ever find yourself repeating the same comments, you’ll save some time by creating a saved reply. The next time you find you’re going to type that comment again, you can instead just select it from a drop-down menu:

To perform the above action without using my mouse, I can do ctrl + /followed by ctrl+ 1.

Conclusion

Thanks for reading. I hope you found at least one thing on this page that will make you a more productive GitHub user. If you enjoyed this post or have any feedback in general, let me know!


If you’re interested in more content like this, follow me on Twitter.

Originally posted on my blog.

P.S. You can make your own Octocat for sharing like the one in the cover photo at myoctocat.com!


By :Darren Burns


Understanding of GitHub and Actions to Improve Your Workflow

Understanding of GitHub and Actions to Improve Your Workflow

If you host your code on GitHub, you can take advantage of GitHub Actions. Instead of running all tests and linters manually, you can leverage GitHub Actions for those tasks. Learn more Github Actions in this post, improve Your Workflow With These 4 GitHub Actions

Github Actions - What, Why, and How?

Automate boring tasks with Github Actions

GitHub Actions make it easy to automate all your software workflows. Github Actions let you build, test, and deploy your code right from GitHub. You can also assign code reviews, manage branches, and triage issues the way you want with actions.

Whether you want to build a container, deploy a web service, or automate welcoming a new user to your open-source project — there’s an automated action for that.

The easiest way is to think of Github Actions as their own continuous integration system. You can pair GitHub Packages with Actions to simplify package management, including version updates, fast distribution with the Github global CDN, and dependency resolution, using your existing GITHUB_TOKEN.

Getting Started

Every Github repository now supports Github's actions. Open a repository in the browser, and you’ll spot the “Actions” tab right away.

Source: Github

Once we press on the Actions tab, we’ll be taken to the Actions page.

Actions tabs

Github is smart enough to recommend relevant actions. Let’s say we have a Node project where we want to test whether the build command works before shipping our code to the production server. Press on the “set up on this workflow” button.

nodejs.yml

Every Github action required a .yml file. The .yml file is used to describe actions, behavior, and everything else.

.yml stands for YAML (“YAML Ain’t Markup Language”), which is a human-readable data serialization language. It’s commonly used for configuration files and in applications where data is being stored or transmitted.

Before committing the freshly created nodejs.yml file, Github gives us a chance to glance over it. Everything seems in order, and here’s what’s happening inside the file:

  • Spin up a Ubuntu server
  • Install Node.js
  • Install node packages for the project
  • Fire off the package.json scripts like npm run build and npm run test

Alrighty, let’s commit the file to the project now.

Committing the nodejs.yml file

Now every time you push to the project, the commands will fire off automatically. There’s even action for deploying to AWS or Google Cloud.

Checks running on each push

Github actions aren’t just for the Web or Node exclusively — they’re also for languages and environments. Explore all the actions here.

The best part about actions is you can write your own action and open-source it for the whole world to see.

Improve Your Workflow With These 4 GitHub Actions

Here are 4 useful GitHub Actions to improve your workflow

1. Detect Secret Key Leaks — gitleaks-action

Audit Git commits for secrets with gitleaks, as a GitHub action. If you use .env files, this action notifies you if you ever published the secrets by accident.

Gitleaks-action — https://github.com/eshork/gitleaks-action

Usage

workflow "gitleaks my commits" {
  on = "push"
  resolves = ["gitleaks"]
}
action "gitleaks" {
  uses = "eshork/[email protected]"
}

Credit to zricethezav/gitleaks for the complicated bits.

2. Audit Your Webpage With Google Chrome’s Lighthouse Test

This action integrates Google’s helpful Lighthouse audits for webpages — specifically testing for performance, accessibility, best practices, SEO, and progressive web apps.

*Github Lighthouse Action — https://github.com/marketplace/actions/lighthouse-audit

Right now, the action will print the five scores (out of 100) to the output and upload HTML and JSON versions of the report as artifacts.

In the next release, the action will let you specify thresholds for each test and optionally fail this step if they are not met.

Lighthouse audit report example

Usage

The following workflow runs a Lighthouse audit on jarv.is, shows the five scores in the output of the step, and uploads the .html and .json results as artifacts to download (as shown above).

workflow.yml file:

name: Audit live site
on: push
jobs:
  audit:
    runs-on: ubuntu-latest
    steps:
    - name: Audit live URL
      uses: jakejarvis/[email protected]
      with:
        url: 'https://jarv.is/'
    - name: Upload results as an artifact
      uses: actions/[email protected]
      with:
        name: report
        path: './report'

Lighthouse is super useful when you’re building progressive web apps. The project is inspired by GoogleChromeLabs/lighthousebot.

3. Run SSH Commands With GitHub Actions

This action will run the provided argument as a command on your $HOST via SSH. Useful if you want to run commands on your private server after each commit or push.

SSH GitHub Action — https://github.com/maddox/actions/tree/master/ssh

Usage

To use the action, simply add the following lines to your .github/main.workflow:

action "Run deploy script" {
  uses = "maddox/actions/[email protected]"
  args = "/opt/deploy/run"
  secrets = [
    "PRIVATE_KEY",
    "HOST",
    "USER"
  ]
}

Required arguments

The argument you will use is the command that will be run on your server via SSH.

Examples

  • args = "/opt/deploy/run"
  • args = "touch ~/.reload"

Required secrets

You’ll need to provide some secrets to use the Action.

  • PRIVATE_KEY: Your SSH private key.
  • HOST: The host the action will SSH to run the command. For example, your.site.com.
  • USER: The user the SSH command will auth as with the private key.

Please see the GitHub repository for full details.

4. GitHub Action That Runs ESLint

Eslint Action — https://github.com/stefanoeb/eslint-action

This action executes the ESLint linter on specified JavaScript files without any previous action/build step or Docker required.

You must have the ESLint running locally for the Action to execute. It will use the same rules as you do locally. More info in the ESLint getting started guide

Usage

Add any of the examples below to your workflow file .github/main.workflow.

Here’s an example to get it to work:

workflow "New workflow" {
  on = "push"
  resolves = ["ESLint"]
}
action "ESLint" {
  uses = "stefanoeb/[email protected]"
}

By default, it will run ESLint through all the files in the project. But you can also specify a glob of files on the args, just like ESLint:

workflow "New workflow" {
  on = "push"
  resolves = ["ESLint"]
}
action "ESLint" {
  uses = "stefanoeb/[email protected]"
  args = "index.js src/**.js"
}

If there is no previous step installing the necessary modules, this action will execute a yarn install or npm install automatically.

You may also like: GitHub Development Workflow - Developers need to know.

Conclusion

Thanks for reading, I hope you learned something new. If you know any useful GitHub Actions, let us know. Stay curious and happy coding!