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
Git

Git got to a particular hash version

Use git checkout <sha1> to check out a particular commit.

Categories
Git

How to easily copy one git branch to another local branch ?

git checkout local-branch-i-want-to-revert
git reset --hard origin/branch-i-want-to-copy
Categories
Git

Tutorial – Submit large files in GIT

INSTALL LFS ON RHEL/CentOS

  1. Install git >= 1.8.2
    • Recommended method for RHEL/CentOS 5 and 7 (not 6!)
      1. Install the epel repo link (For CentOS it’s just sudo yum install epel-release)
      2. sudo yum install git
    • Recommended method for RHEL/CentOS 6
      1. Install the IUS Community repo. curl -s https://setup.ius.io/ | sudo bash or here
      2. sudo yum install git2u
    • You can also build git from source and install it. If you do that, you will need to either manually download the git-lfs rpm and install it with rpm -i --nodeps git-lfs*.rpm, or just use the Other instructions. The only other advanced way to fool yum is to create and install a fake/real git rpm to satisfy the git >= 1.8.2 requirement.
  2. To install the git-lfs repo, run curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash from here
  3. sudo yum install git-lfs
  4. git lfs install

Install software on your Macbook MAC

brew install git-lfs

List type files to be tracked

git lfs track "*.psd"

git add .gitattributes

Example

git add file.psd 

git commit -m "Add design file" 

git push origin master
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]

#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

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 add new ssh key to 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

How to GIT ERROR: Repository not found. ?

$ git push origin master

ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
  and the repository exists.

Solution

Critical command line to address the issue –

Ensure ssh-agent is enabled:

Start the ssh-agent in the background

eval "$(ssh-agent -s)"
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/*