Skip to content

Instantly share code, notes, and snippets.

@masroorhussainv
Last active May 12, 2022 14:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save masroorhussainv/1d47a84d1e3ccbb8742aa476d286f1ed to your computer and use it in GitHub Desktop.
Save masroorhussainv/1d47a84d1e3ccbb8742aa476d286f1ed to your computer and use it in GitHub Desktop.

Git commands

Set up Name and Email

git config user.email 'email@example.com'
git config user.name 'Masroor Hussain'

Create a repo

git init

Remotes

Check remotes

git remote -v

Add remote

git remote add origin remote_url_here

Add PAT(Personal Access Token)

  • First you need to add the remote(see the step above to add a remote), then update it's url with PAT in it
git remote set-url origin https://repo_owner_username_here:put_token_here@github.com/repo_owner_username_here/repo_name_here.git

Permanently delete repo from local storage

rm -rf .git

Add files to staging(ready to be committed)

git add filename

or to add all files do the following:

git add . 

Remove file from staging area

git restore HEAD filename

Create a commit

git commit -m 'message here'

Create diff file from unstaged files

git diff > unstaged.diff

Create diff file from staged files

git diff --staged > staged.diff

Apply diff changes from a file

git apply filename.diff

Reset the latest commit

git reset --soft HEAD~1

Reset N commits

git reset --soft HEAD~N

Delete a branch from remote

git push remote_name :branch_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment