GitLab Commands

GitLab Commands Cheat Sheet: Essential Git Commands & Shortcuts.

Git commands

git config --global credential.helper store

Configures Git to store credentials (username and token) permanently in plaintext on disk, so you don't have to re-enter them every time.

rm ~/.git-credentials

Removes the stored Git credentials file from disk, effectively deleting the saved username/token.

git config --global --unset credential.helper

Unsets the credential helper configuration so Git stops automatically using saved credentials.

git clone <repository_url>

Clones a remote repository to your local machine.

git init

Initializes a new Git repository in the current directory.

git status

Displays the status of the working directory and staged changes.

git add <file>

Stages a specific file for commit.

git add .

Stages all changes in the current directory for commit.

git commit -m 'commit message'

Commits the staged changes with a descriptive message.

git push origin <branch_name>

Pushes committed changes to the remote repository.

git pull origin <branch_name>

Fetches and merges changes from the remote repository.

git branch

Lists all branches in the repository.

git branch <branch_name>

Creates a new branch.

git checkout <branch_name>

Switches to a different branch.

git checkout -b <new_branch>

Creates and switches to a new branch.

git merge <branch_name>

Merges the specified branch into the current branch.

git rebase <branch_name>

Reapplies commits from the current branch onto the specified branch.

git reset --hard <commit_id>

Resets the working directory to a specific commit, discarding all changes.

git reset --soft <commit_id>

Resets to a specific commit but keeps changes staged.

git reset --soft HEAD~1

Resets the last commit but keeps the changes staged.

git reset --hard HEAD~1

Resets the last commit and discards all changes.

git stash

Temporarily stores uncommitted changes.

git stash pop

Applies the most recent stashed changes and removes them from stash.

git log

Displays commit history.

git log --oneline

Shows commit history in a compact format.

git diff

Shows differences between working directory and staged files.

git tag <tag_name>

Creates a tag for a specific commit.

git push origin --tags

Pushes local tags to the remote repository.

git rm <file>

Removes a file from the working directory and stages the removal.

git revert <commit_id>

Creates a new commit that undoes a previous commit.

git remote -v

Lists all remote repositories linked to the local repository.

git remote add origin <repository_url>

Adds a remote repository reference.

git fetch origin

Fetches changes from the remote repository but does not merge them.

git cherry-pick <commit_id>

Applies a specific commit from another branch.