Fundamentals 11 min read

Master Git in 15 Minutes: Essential Commands for Everyday Projects

This guide walks you through installing Git, configuring your identity, creating remote and local repositories, staging and committing changes, managing branches, merging, discarding, rolling back, pushing to and pulling from remote servers, and setting up handy command aliases, all with clear examples.

21CTO
21CTO
21CTO
Master Git in 15 Minutes: Essential Commands for Everyday Projects

Workflow Steps

This article demonstrates a complete Git workflow that can be performed on a single machine or across multiple machines.

Install Git

On most Unix-like systems Git is pre‑installed; you can update to the latest development version with: git clone https://github.com/git/git Windows users can download the installer from the official site.

Create a Remote Repository

Register an account on Bitbucket (or GitHub) and create a private repository. After logging in, click the “Create” button and enable the private option.

Configure Git

Set your username and email (preferably the same as your Bitbucket account) with:

git config --global user.name "your_username"
git config --global user.email [email protected]

Also set the default push behavior:

git config --global push.default simple

Create a Local Repository

Navigate to your project folder and initialize a repository:

cd ~/workspace/my_site/
git init

This creates a hidden .git directory.

Stage Files

Add all files to the staging area: git add . Or add specific files:

git add my_file my_other_file

Commit Files

Commit the staged files with a meaningful message: git commit -m "initial commit" Check the status at any time with:

git status

Create a Branch

Create and switch to a new branch: git checkout -b new_feature List all branches:

git branch

Merge a Branch

After finishing work on the feature branch, stage and commit any changes, then switch back to master and merge:

git add .
git commit -m "adds my new feature"
git checkout master
git merge new_feature

Discard a Branch

If you want to discard changes, commit them, switch to master, then delete the branch:

git add .
git commit -m "feature to be discarded"
git checkout master
git branch -d new_feature

Use -D to force‑delete an unmerged branch.

Delete a Branch

git branch -d new_feature
git branch -D new_feature

Rollback to a Previous Commit

List commits with: git log Checkout a specific commit (using the first 9 characters of its SHA): git checkout 085bb3bcb Or create a new branch from that commit:

git checkout -b my_previous_version 085bb3bcb

Push to a Remote Repository

Add the remote origin (replace placeholders with your credentials):

git remote add origin https://[email protected]/your_username/name_of_remote_repository.git

Push the master branch:

git push origin master

Clone or Pull a Remote Repository

Clone a repository to a new machine:

git clone https://[email protected]/your_username/name_of_remote_repository.git

Or pull the latest changes into an existing local project:

git pull origin master

Aliases

Create shortcuts for frequently used commands, for example:

git config --global alias.c 'commit -m'
git config --global alias.co 'checkout'
git config --global alias.cob 'checkout -b'
git config --global alias.br 'branch'
git config --global alias.m 'merge'
git config --global alias.a 'add .'
git config --global alias.s 'status'
git config --global alias.dbr 'branch -d'
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

branchingMergingremote repository
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.