0% found this document useful (0 votes)
12 views

Github Cookbook

This document provides a cookbook of common Git commands organized into sections on configuration, repository setup, basic operations, branching and merging, stashing and cleaning, tagging, log and history, advanced Git, and GitHub integration. Each section lists commands and provides usage examples.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Github Cookbook

This document provides a cookbook of common Git commands organized into sections on configuration, repository setup, basic operations, branching and merging, stashing and cleaning, tagging, log and history, advanced Git, and GitHub integration. Each section lists commands and provides usage examples.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

GitHub Commands Cookbook (Updated)

Git Configuration Commands

git config

Setting user name, email, and default editor

Usage:

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

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

git alias

Creating shortcuts for common commands

Usage:

1. git alias st status

2. git alias ci commit


Repository Setup

git init

Initializing a new repository

Usage:

1. git init

2. git init new_repo

git clone

Cloning an existing repository

Usage:

1. git clone https://github.com/user/repo.git

2. git clone https://github.com/user/repo.git local_dir


Basic Git Operations

git add

Adding files to the staging area

Usage:

1. git add .

2. git add filename.txt

git commit

Committing changes

Usage:

1. git commit -m 'Initial commit'

2. git commit -a -m 'Update files'

git status

Checking the status of the repository

Usage:

1. git status

2. git status -s

git push

Pushing changes to a remote repository

Usage:

1. git push origin master

2. git push -u origin master


git pull

Pulling changes from a remote repository

Usage:

1. git pull origin master

2. git pull

git fetch

Fetching changes from a remote repository

Usage:

1. git fetch origin

2. git fetch --all


Branching and Merging

git branch

Creating, listing, and deleting branches

Usage:

1. git branch new-branch

2. git branch -d old-branch

git checkout

Switching branches

Usage:

1. git checkout new-branch

2. git checkout -b new-branch

git merge

Merging branches

Usage:

1. git merge feature-branch

2. git merge feature-branch --no-ff

git rebase

Rebasing a branch

Usage:

1. git rebase master

2. git rebase -i HEAD~3


Stashing and Cleaning

git stash

Stashing changes temporarily

Usage:

1. git stash

2. git stash apply

git clean

Removing untracked files

Usage:

1. git clean -n

2. git clean -f
Tagging

git tag

Creating, listing, and deleting tags

Usage:

1. git tag v1.0

2. git tag -a v1.0 -m 'Version 1.0'


Log and History

git log

Viewing the commit history

Usage:

1. git log

2. git log --oneline

git blame

Showing who changed what and when in a file

Usage:

1. git blame filename.txt

2. git blame -L 15,25 filename.txt


Advanced Git

git cherry-pick

Applying changes from a specific commit

Usage:

1. git cherry-pick commit_hash

2. git cherry-pick commit_hash1 commit_hash2

git revert

Reverting changes from a commit

Usage:

1. git revert HEAD

2. git revert commit_hash

git rebase -i

Interactive rebase

Usage:

1. git rebase -i HEAD~3

2. git rebase -i --autosquash commit_hash

git bisect

Finding the commit that introduced a bug

Usage:

1. git bisect start

2. git bisect reset


Git and GitHub Integration

git remote

Managing remote repositories

Usage:

1. git remote add origin https://github.com/user/repo.git

2. git remote -v

git pull request

Creating a pull request

Usage:

1. git pull request

2. git pull request -b master -h feature-branch

git fetch upstream

Fetching changes from the upstream repository

Usage:

1. git fetch upstream

2. git fetch upstream master

You might also like