Handy Git command

0 votes
added Jul 21, 2017 in Git by anonymous
edited Aug 6, 2018 by LC Marshal
git init
//create a new repository

clone with HTTPS
//git clone <git_url>

git clone & checkout to your own desired branch
//git clone <git_url> my-own-branch

git clone username@host:/path/to/repository 
//When clone with remote server

git clone -b <git_url> --single-branch 
//Clone and switch new branch

git checkout -b <feature_name>
//Create and checkout to a new branch "feature_name"

git checkout master
//Checkout to master

git branch -d <feature_name>
//Delete the "feature_name" branch

git branch -d branch1 branch2 branch3 branch4
//Delete multiple branches at a time

git branch -u origin/mybranch
//Delete local branch

git branch -m [<old-branch-name>] <new-branch-name> 
//Rebases 'feature' to 'master' and merges it in to master

git add <filename>
//To add files

git add .
//To add all unstage files

git add <yourfolder/filename> 
//To add folder to repository

git commit -m "Commit message"  
//Now the file is committed to the HEAD, but not in your remote repository yet.

git commit -am "my commit message"  
//To stage and commit with message 

git push origin master
//pushing changes - Your changes are now in the HEAD of your local working copy. To send those changes to your remote 

git remote add origin <server>
//If you have not cloned an existing repository and want to connect your repository to a remote server, you need to add it with
- Now you are able to push your changes to the selected remote server

git pull  
//Update local repository to latest commit.

git merge <branch>  
//Merge another branch into your active branch.

git commit -v --amend 
//See commit history for just the current branch

git branch -a 
//Get only remote branches

git stash --  
//remove unwanted changes

git stash save  
//Saving current state of unstaged changes to tracked files

git stash --all git stash save --all
//Show list of all saved stashes

git ls-files -t 
//Show all untracked files

git ls-files --others 
//Show all ignored files

git clean -n  
//Forcefully remove untracked files

git clean -f  
//Forcefully remove untracked directory

git clean -X -f 
//Restore deleted file.

git config --list 
//Make git case sensitive.

git checkout --orphan <branch_name> 
//Extract file from another branch.

git push -f <remote-name> <branch-name> 
//Adding remote name

git diff  
//diff of what is changed but not staged

git log 
//show all commits in the current branch’s history
git help gc //manual housekeeping

3 Responses

0 votes
responded Jul 24, 2017 by LC Marshal Captain (25,790 points)
Click the following link for more git cheatsheet provide by Github.

0 votes
responded Jul 31, 2017 by anonymous

git add . 
git add -A

Add all files to index/commit

git status
Review your changes

git pull
Get latest version

0 votes
responded Aug 9, 2017 by Callum Sergeant (1,440 points)

git commit -am "my commit message"

To stage and commit with message 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.