This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Git & Common Git Providers

A comprehensive guide to understanding and working with Git version control system.

Git Documentation

Welcome to the Git documentation. This guide will help you understand and work with Git version control system.

Table of Contents

Basic Commands

CommandDescription
git initInitialize a new Git repository
git clone <url>Clone a repository from remote source
git add <file>Add file(s) to staging area
git add .Add all modified files to staging area
git commit -m "message"Commit staged changes with a message
git statusShow working tree status
git logShow commit history
git diffShow changes between commits, commit and working tree, etc.

Branching and Merging

CommandDescription
git branchList all local branches
git branch -aList all branches (local and remote)
git branch <branch-name>Create a new branch
git checkout <branch-name>Switch to specified branch
git checkout -b <branch-name>Create and switch to a new branch
git merge <branch-name>Merge specified branch into current branch
git branch -d <branch-name>Delete a branch

Remote Repositories

CommandDescription
git remote -vList all remote repositories
git remote add <name> <url>Add a new remote repository
git push <remote> <branch>Push branch to remote repository
git pull <remote> <branch>Pull changes from remote repository
git fetch <remote>Download objects and refs from remote

Advanced Operations

CommandDescription
git stashStash changes in working directory
git stash popApply stashed changes and remove from stash
git reset --hard <commit>Reset working directory to specified commit
git rebase <branch>Reapply commits on top of another base
git cherry-pick <commit>Apply changes from specific commit
git tag <name>Create a tag

Configuration

CommandDescription
git config --global user.name "Name"Set global username
git config --global user.email "email"Set global email
git config --listList all configuration
git config --global alias.<alias-name> <git-command>Create command alias

Common Workflows

Feature Branch Workflow

  1. Create a feature branch: git checkout -b feature-name
  2. Make changes and commit: git add . and git commit -m "message"
  3. Push to remote: git push origin feature-name
  4. Create pull request (via web interface)
  5. After review, merge to main branch

Fixing Mistakes

  • Amend last commit: git commit --amend
  • Undo last commit (keeping changes): git reset HEAD~1
  • Discard all local changes: git reset --hard
  • Discard changes to a file: git checkout -- <file>

1 - GitLab