Categories
Git

GIT : How to discard all local changes within a branch ?

RESET BRANCH/FILE

-- force discard —
git reset --hard origin/<davidBranch_name>

example with the master branch


git reset --hard origin/master
Categories
Git

Undo ‘git add’ safely ?

You can undo git add before commit with

git reset <file>
or
git reset <directory>

It will not delete any of your files

.gitignore could be useful before executing git add *

  • Step 1
touch .gitignore
  • Step 2
.DS_Store
/vendor

Categories
Continuous Integration/Development Git

How to resolve GITHUB key already in use ?

Find out which repository is already in use

ssh -T -ai ~/.ssh/id_rsa [email protected]

Solution 1

#1 Remove the key from your GITHUB repository->deploy

#2 Copy your key from macbook

pbcopy < ~/.ssh/id_rsa.pub

#3 Paste your key in the Github->repository you want to use

Solution 2

you can do a do a git clone against the https url

git clone https://git.com/david/global-helpers.git

Categories
Git

How to fix GIT (modified content) ?

Here is the command on how to resolve (modified content)

git rm -rf --cached yourfolder

Categories
Git

How to resolve Git error when pushing – update_ref failed ?

$ rm -rf .git/refs/remotes/origin      # remove all origin/*
$ mkdir .git/refs/remotes/origin       # create empty origin/
$ git fetch origin                     # repopulate origin/*
Categories
Technical

git pull origin master returns fatal: invalid refspec


remove lines below from .git/config[remote “origin”]


        url = [email protected]:dxxxx/xxxxxxxx.git
        fetch = +refs/heads/*:refs/remotes/origin/*

Type following commands

 git remote add origin [email protected]:xxxxxx/xxx.git
 git remote -v
Categories
Operating System Version-control system

Where to find GIT command Helper ?

Successful Git Connection

ssh -Tvvv [email protected]

Copy Shh key from Macbook

pbcopy < ~/.ssh/id_rsa.pub

Generate SSH Key Github

$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_rsa (regular unix system)
$ ssh-add -K ~/.ssh/id_rsa (for macbook)

$ pbcopy < ~/.ssh/id_rsa.pub (for macbook)

Paste key into github

$ git remote add origin [email protected]:xxxxxx/xxxxxxx.git  
$ git remote -v 
$ git push -u origin master

SETUP REMOTE GIT

 git init
 git add .
 git status
 git commit -m "First commit"
 git remote add origin [email protected]:xxxxxx/xxxxxxx.git
 git remote -v
 git push -u origin master

Add Key to github

cat ~/.ssh/authorized_keys 
cat ~/.ssh/known_hosts 

SYNC GIT

git remote update

git fetch Downloads the latest from remote without trying to merge or rebase anything.

git fetch -- all

REMOVE untracked files

git clean -f -d

RESET BRANCH/FILE

-- force discard local changes —
git reset --hard origin/master 
-- force discard —
git reset --hard origin/<davidBranch_name> 
git checkout -f <localfile> 

COMMIT

git commit -m ‘My commit David Raleche’

Amend a COMMIT

git commit --amend

remove git add

git reset HEAD -file-

PUSH

git push origin <davidBranch>

CONFLICTED FILES

git diff --name-only --diff-filter=U GIT ADD git add <file> git commit -m “message of your commit” git push origin

GIT RESET ADD

git reset <file> git reset

(VERY DANGEROUS) REMOVING LAST COMMIT (VERY DANGEROUS)

git reset --soft HEAD~1
git reset --hard HEAD^

(VERY DANGEROUS)

GIT CHECKOUT SOMEONE ELSE REPO

git checkout --track origin/ECOM-307

Git Diff

git diff –name-only –diff-filter=U

Git log HELPER

git log –graph git log –oneline