GitHub commands

Initialize as a Git repository

git init

Config Setup. User namd and email

git config --global user.name "xyz"
git config --global user.email "xyz@example.com"
git config --list

Connect local repository to GitHub repository

git remote add origin http://github.com/username/test.git
git remote -v

Push and Pull

git push origin master
git pull origin master

Ignore

vim .gitignore

 

Clone

Creates a new folder

git clone https://github.com/username/test.git

Clone to current directory

git clone https://github.com/username/test.git .

 

Fetch

git clone https://github.com/username/test.git

Merge

git clone https://github.com/username/test.git

Pull

git clone https://github.com/username/test.git

 

Reset

git reset --soft HEAD^
git reset --hard HEAD^

 

 

Frequently used commands

Add to commit later

git add .
git add A

Get current status before commit

git status

Commit

git commit -m "My First commit"

Commit shortcut

git commit -am "My First commit"

Reset (removes all files from staging area)

git reset

Branch

List which branch you are working on

git branch
git branch -a

Create new branch

git branch whatever

Use this branch

git checkout whatever

Push to branch

git push -u origin whatever

Merge

Switch to master branch

git checkout master

Pull latest master

git pull origin master

View merged branch so far

git branch --merged

Merge

git merge whatever

Push to master

git push origin master

Delete branch

View branch merged

git branch --merged

Delete branch

git branch -d whatever

view all branch

git branch -a

Action to delete branch in GitHub

git push origin --delete whatever

Leave a Comment

Your email address will not be published. Required fields are marked *