Skip to content

Instantly share code, notes, and snippets.

@Nabil5352
Last active August 25, 2019 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nabil5352/aed8c7d9ec453b1fde7235a6ea36a139 to your computer and use it in GitHub Desktop.
Save Nabil5352/aed8c7d9ec453b1fde7235a6ea36a139 to your computer and use it in GitHub Desktop.
Github command collection

LOCAL MACHINE CONFIGURATION:

  1. --local local to that repository only
  2. --global global to that machine

Set email

git config --global user.email "mail@example.com"`

Set username

git config --global user.name "your_user_name"

Automatically prune during fetch/pull

git config remote.origin.prune true

REPOSITORY FORMAT:

https://github.com/[username]/[repository-name].git

CLONING AN EXISTING REPOSITORY

git clone https://github.com/[username]/[repository-name].git

INITIALIZING A NEW REPOSITORY

git init
git add .
git commit -m "first commit"
git remote add origin https://github.com/[username]/[repository-name].git
git push -u origin master

PUSH TO AN EXISTING REPOSITORY

git remote add origin https://github.com/[username]/[repository-name].git
git push -u origin master

CREATE BRANCH

  1. -b if not exists create a new one
git checkout -b [branch name]

SEE BRANCH LIST

  1. -a local
  2. -r remote
git branch -a

SYNC BRANCH BETWEEN LOCAL AND REMOTE

git fetch --all --prune

CHANGE BRANCH

git checkout [branch name]

MERGE BRANCH

git checkout [main branch]

merge another branch to master 1.--no-ff keep track who did the merge 2. Add an optional commit message using this commands

git merge --no-ff [branch name]

COMPARE TWO BRANCH

git diff branch_1...branch_2

DELETE BRANCH

  1. -d means --delete only deletes the branch if it has already been fully merged in its upstream branch
  2. -D means --delete --force deletes the branch irrespective of its merged status
git branch -d branch_name
git branch -D branch_name

or

git push <remote_name> :<branch_name>
Ex. git push origin :branch-name-to-delete

Then use sync command to update branch list with remote.

COMMIT

undo last commit

git reset HEAD~

remove all local commit

git reset --hard origin/<branch-name>

GIT EDITOR (vim)

press "i"
write your merge message
press "esc"
write ":wq"
then press enter

OTHERS

shows SHA1 id and branch names

git remote --heads origin

IF ACCIDENTALLY PUSHED SECRET INFORMATION TO GITHUB

follow this instruction step by step

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment