Skip to content

Instantly share code, notes, and snippets.

@MKRNaqeebi
Last active September 4, 2020 11:43
Show Gist options
  • Save MKRNaqeebi/e94f94f8f8be4691a3c8d7696aa0ecb4 to your computer and use it in GitHub Desktop.
Save MKRNaqeebi/e94f94f8f8be4691a3c8d7696aa0ecb4 to your computer and use it in GitHub Desktop.
git cheat sheet for me daily to use daily instead of doing google daily for git command I want to manage this sheet and use for future

git command & cheatsheet

Git configuration:

 git config --global user.name "Muhammad Kamran"
 git config --global user.email "mkrnaqeebi@gmail.com”

New git repository:

git init project.name
git clone git.url/here

Attach local to remote:

git remote add origin git.url/here
git remote add name git.url/here

Replace remote:

git remote set-url origin new.git.url/here

List remote:

git remote -v

List all commands

to see all the commands in git simply use the git --help

Displays the status of your working directory

git status

Add file or directory to staging area

git add file.ext
git add .

Show changes between working directory and staging area

git diff file.ext

Shows any changes between the staging area and the repository

git diff --staged file.extt

Discard changes in working directory

git checkout -- file.ext

Revert your repository to a previous known working state

git reset file.ext

Create a new commit from changes added to the staging area

git commit -am 'commit message'

Remove file from working directory and staging area

git rm file.ext

Put current changes in your working directory into stash for later use

git stash

Apply stored stash content into working directory, and clear stash.

git stash pop

Delete a specific stash from all your previous stashes.

git stash drop

Put current changes in your working directory into stash for later use

git stash

Git branching

Remove file from working directory and staging area.

List all local branches in repository. With -a: show all local and remote branches

git branch

Create new branch, referencing the current HEAD

git branch new-branch

Switch working directory to the specified branch. With -b: Git will create the specified branch if it does not exist

git checkout -b new-or-old-branch

Join specified branch into your current branch (the one you are on currently).

git merge my-branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment