Getting Started on GitHub, GitLab and Bitbucket

Updated · 11 min read
easyGit 2.53gitgithubgitlabbitbucketcredentialsinterview

A shared office building gives every company more than a room. There is a reception desk, meeting rooms, a noticeboard and a security guard who checks who comes in. Each company still does its own work, but the building makes working together much easier.

GitHub, GitLab and Bitbucket are buildings like that for Git repositories. Each one stores your repository on its servers, the same kind of server copy you used in the previous module, and adds what a team needs around it: a web page for every file and commit, pull requests for reviewing changes, issues for tracking work, permissions for who may push, and automated builds. Git itself is the same on all three. What differs is the website and a few names.

In this lesson, you will create a repository on a platform, connect a local project to it, push, and set up your computer so that Git can sign in.

Git Is Not GitHub

This is worth repeating from "Git vs GitHub, GitLab and Bitbucket": Git is the tool on your computer, and it works without any website. GitHub, GitLab and Bitbucket are services that host Git repositories and add collaboration features. Every Git command in this course works the same with all three.

GitHubGitLabBitbucket
Owned byMicrosoftGitLab Inc.Atlassian
Review request is calledPull requestMerge requestPull request
Built-in automationGitHub ActionsGitLab CI/CDBitbucket Pipelines
Can run on your own serversGitHub Enterprise ServerGitLab Self-ManagedBitbucket Data Center
Often chosen byOpen-source projects, most teamsTeams that want everything in one tool, or self-hostingTeams that use Jira and Confluence

This course says "pull request" for all three. On GitLab, read it as "merge request".

Create a Repository on the Platform

After signing up for a free account, create a new, empty repository. The steps on each platform:

text
1. Click + (top right) and choose New repository.
2. Repository name: fee-tracker
3. Choose Public or Private.
4. Leave "Add a README", ".gitignore" and "license" unchecked,
   because you will push an existing project.
5. Click Create repository.

Each platform then shows the repository's URL, in an HTTPS and an SSH form, and the commands to push an existing project. Those are the commands from "Git Remote":

PlatformHTTPS URLSSH URL
GitHubhttps://github.com/<user>/fee-tracker.gitgit@github.com:<user>/fee-tracker.git
GitLabhttps://gitlab.com/<user>/fee-tracker.gitgit@gitlab.com:<user>/fee-tracker.git
Bitbuckethttps://bitbucket.org/<workspace>/fee-tracker.gitgit@bitbucket.org:<workspace>/fee-tracker.git

Connect and Push

On her computer, Navika prepares the project with the files every good repository has, then connects it and pushes. As in the remote lessons, a bare repository in a folder stands in for the platform, because this page can't sign in to a real one. With a real platform, only the URL changes:

Terminal
git init --bare --quiet github-fee-tracker.git
mkdir fee-tracker
cd fee-tracker
git init --quiet
printf "# Fee Tracker\n\nTracks school fee payments.\n" > README.md
echo "Copyright (c) 2026 Navika Anamaneni. All rights reserved." > LICENSE
echo "target/" > .gitignore
git add .
git commit --quiet -m "Start the Fee Tracker project"
git remote add origin ../github-fee-tracker.git
git push -u origin main
Output
To ../github-fee-tracker.git
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.

Refresh the repository page in the browser, and the files and the commit appear. The platform shows README.md as the project's front page.

FileWhy a repository should have it
README.mdThe front page: what the project is, how to run it, how to contribute
LICENSEWho may use the code, and how. Without one, others may not legally reuse it. Platforms offer standard licenses (MIT, Apache 2.0) when you create a repository.
.gitignoreKeeps build output and secrets out, as in "Git .gitignore"
CONTRIBUTING.mdHow to report bugs, propose changes and set up the project

Tokens Instead of Passwords for HTTPS

The first time Git talks to a real platform over HTTPS, it asks for a username and a password. Your account password doesn't work for Git. Each platform requires a token that you create on its website and paste in place of the password:

text
Username: your GitHub username
Password: a personal access token
 
Create one: profile picture > Settings > Developer settings
> Personal access tokens. A fine-grained token limited to
the repositories you need, with "Contents: Read and write",
is enough for clone, pull and push.

Treat a token like a password: it gives access to your repositories. Give it an expiry date and only the permissions it needs. And don't type it every time: let a credential helper remember it.

Signing in over HTTPS with a token

Credential Helpers

A credential helper stores the token safely after the first successful sign-in, in your operating system's password store, and gives it to Git automatically from then on:

Shell
# Installed and switched on by Git for Windows (Git Credential Manager)
git config --global credential.helper manager

Git Credential Manager (GCM), included with Git for Windows and available for macOS and Linux, can also sign in to GitHub, GitLab and Bitbucket through the browser, so you may never need to copy a token at all. On Linux, pick one of the two lines above.

Never put the token inside the remote URL (https://user:token@github.com/...). It is then stored in plain text in .git/config, and appears in every git remote -v.

Syntax

CommandIt is used to
git remote add origin <url>Connect a local project to the platform repository
git push -u origin mainPush for the first time
git clone <url>Copy a platform repository to your computer
git config --global credential.helper <helper>Let Git remember your token
git config --global --get credential.helperSee which credential helper is set

Common Mistakes

Typing your account password when Git asks for one. Platforms reject it for Git over HTTPS. Use a token, or SSH.

Creating the platform repository with a README, then pushing an existing project. The push is rejected because the histories are unrelated. Create it empty, or run git pull --allow-unrelated-histories origin main once to join them.

Storing a token in the remote URL. It sits in plain text in .git/config. Use a credential helper.

Pushing private keys, passwords or .env files to a public repository. Bots scan public platforms for secrets within minutes. Add them to .gitignore before the first commit.

No README. Visitors, and you in six months, can't tell what the project is or how to run it.

Under the Hood

A hosting platform stores each repository as a bare repository on its servers, like the folder used on this page, and runs Git's server programs for clone, fetch and push. Over HTTPS, your Git sends each request with the credentials the helper provided, and the platform checks them before running the request. When the push arrives, the platform updates its database, the web pages, and starts any automation, such as builds and pull request checks, configured for the repository.

Interview Corner

What is the difference between Git and GitHub?

Git is a distributed version control system that runs locally. GitHub is a hosting service for Git repositories that adds a web interface and collaboration features such as pull requests, issues, permissions and CI. GitLab and Bitbucket are similar services.

How do you push an existing local project to a new GitHub repository?

Create an empty repository on GitHub, then in the project run git remote add origin <url> and git push -u origin main.

Why doesn't your account password work for git push over HTTPS?

GitHub, GitLab and Bitbucket require a personal access token (Bitbucket: an API token) for Git over HTTPS, or SSH keys. Tokens can be limited in scope and expiry, and revoked individually, unlike a password.

What is a credential helper?

A program Git calls to store and retrieve credentials, such as Git Credential Manager or the macOS Keychain helper, configured with credential.helper. It saves the token after the first sign-in so you don't type it again.

Practice

Challenge: second project. Create a second stand-in platform repository, github-fee-receipts.git, and a new project fee-receipts next to fee-tracker, with a README.md containing # Fee Receipts. Connect it, push it with -u, and ask the "platform" which branches it has.

What does Git print? Before you open the solution, decide what the push says on the first push of main, and how many branches git ls-remote --heads lists.

Show solution
Terminal
cd ..
git init --bare --quiet github-fee-receipts.git
mkdir fee-receipts
cd fee-receipts
git init --quiet
echo "# Fee Receipts" > README.md
git add README.md
git commit --quiet -m "Start the Fee Receipts project"
git remote add origin ../github-fee-receipts.git
git push -u origin main
Output
To ../github-fee-receipts.git
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.
Terminal
git ls-remote --heads origin
Output
e18d897767902ed811ecea07bef9e76a58202380	refs/heads/main

The first push creates main on the platform (* [new branch]) and sets the upstream. The platform now has exactly one branch, main.

Checkpoint. Create a free account on GitHub, GitLab or Bitbucket. Create an empty repository, push a small project of your own to it over HTTPS with a token, and let a credential helper remember the token. Check that a second git push doesn't ask for it again.

Quick check: Hosting platforms

4 questions
1What does GitLab call a pull request?
2You push an existing project. How should the new platform repository be created?
3What do you enter as the password when Git asks over HTTPS?
4What does a credential helper do?

Key Takeaways

Quick reference

CommandIt is used to
git remote add origin <url>Connect to the platform repository
git push -u origin mainFirst push
git clone <url>Copy a platform repository
git config --global credential.helper managerUse Git Credential Manager
git config --global credential.helper osxkeychainUse the macOS Keychain
git remote set-url origin <url>Switch between HTTPS and SSH URLs

Was this tutorial helpful?

Lesson 43 of 106