Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
18 views4 pages

CI-Git Cheatsheet-160724-201613

Uploaded by

Ionut Mocoi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

CI-Git Cheatsheet-160724-201613

Uploaded by

Ionut Mocoi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Git Cheatsheet

Commands
Setup and Configuration
Configure User Information
View Configuration
Initialize a New Repository
Clone an Existing Repository
Basic Commands
Check Repository Status
Add Files to Commit
Reverse Add Files
Commit Changes
Branch Commands
List Branches
Switch to a Branch
Create Branches
Merge a Branch Into the Current Branch
Remote Commands
List Remote Repositories
Fetch Changes
Push Changes to a Remote Repository
Pull Changes from a Remote Repository
Stash Commands
List Stashes
Stash Changes
Apply Stashed Changes
Clear All Stashes
Usual Flows
Creating a Feature Branch
Before Making a Pull Request

Commands

Setup and Configuration

Configure User Information

1 git config --global user.name "Your Name"


2 git config --global user.email "[email protected]"

View Configuration

1 git config --list

Initialize a New Repository


1 git init

Clone an Existing Repository

1 git clone <repository_url>

Basic Commands

Check Repository Status

1 git status

Add Files to Commit

1 git add <file> # Add specific file


2 git add . # Add all files

Reverse Add Files

1 git reset <file>

Commit Changes

1 git commit -m "message"


2 git commit -am "message" # Add and commit

Branch Commands

List Branches

1 git branch

Switch to a Branch

1 git checkout <branch_name>

Create Branches

1 git branch <branch_name>


2 git checkout -b <branch_name> # Create and switch to a new branch

Merge a Branch Into the Current Branch

1 git merge <branch_name>


Remote Commands

List Remote Repositories

1 git remote -v

Fetch Changes

1 git fetch
2 git fetch <remote_name> # Fetch changes from a remote repository

Push Changes to a Remote Repository

1 git push
2 git push origin -u <branch_name> # Pushes and sets upstream

Pull Changes from a Remote Repository

1 git pull <branch_name>

Stash Commands

List Stashes

1 git stash list

Stash Changes

1 git stash

Apply Stashed Changes

1 git stash apply

Clear All Stashes

1 git stash clear

Usual Flows

Creating a Feature Branch

1. Update Local Repository


Before creating a new feature branch, ensure your local repository is up to date with the latest changes from the remote repository.

1 git fetch
2 git pull origin development # or the default branch name
2. Switch to the Base Branch
Ensure you are on the branch from which you want to create the new feature branch.

1 git checkout development # or the default branch name

3. Create the Feature Branch


Create a new branch and switch to it in one command.

1 git checkout -b <branch_name>

4. Push Your Branch


Before starting to work, push your branch to the remote repository using the -u argument. This sets the upstream branch, allowing you
to push your changes later by just using git push .

1 git push origin -u <branch_name>

Before Making a Pull Request


Sometimes, before making a pull request to the development branch, it is a good practice to merge the development branch into your
feature branch. This allows you to resolve merge conflicts from the feature branch perspective, which is often easier.

1 git merge development

This cheatsheet was created with the help of ChatGPT, an AI language model by OpenAI.

You might also like