Categories
Git

Git remove large file wrongly committed

git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD
git push
Categories
Git

Build git server

For Debian,

sudo apt update && sudo apt install git

For centos,

sudo yum install git
sudo useradd -r -m -U -d /home/git -s /bin/bash git
sudo su - git
mkdir -p ~/.ssh && chmod 0700 ~/.ssh
touch ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys
git init --bare ~/reponame.git

Git server is ready!

Pushing and Pulling from Local

On the LOCAL

cat ~/.ssh/id_rsa.pub

Add the above id_rsa.pub file content from LOCAL to below authorized_keys file ON THE SERVER

sudo nano /home/git/.ssh/authorized_keys

Create a LOCAL repo

cd /path/to/local/repo
git init .
git remote add origin git@SERVER_IP_ADDRESS:reponame.git
touch test_file
git add .
git commit -m "initial commit"
git push -u origin master
Categories
Git

Unable to connect to github.com

Example Code to run

Git config global URL from git://github.com to https://github.com

git config --global url.https://github.com/.insteadOf git://github.com/

This replaces git: to https:

Solution to Issues such as

bower install stops with error : fatal: unable to connect to github.com

Categories
WordPress WordPress Development

GitIgnore Directory

.gitignore Directory

Example Directory name : uploads

Ignoring ALL folders and files

 # .gitignore
uploads

Result:

# Will Ignore

/uploads # directory
/uploads # file
/example/path/uploads # directory
/example/path/uploads # file

Ignoring only the Root Directory

The correct syntax for that is to put leading and trailing slash:

 # .gitignore
/uploads/

Result:

 # will ignore
/uploads # directory

# will NOT ignore
/uploads              # file
/some/path/uploads    # directory
/another/path/uploads # file

Ignoring only the Root Directory and the Root File

 # .gitignore
/uploads

Result:

# will ignore

/uploads # directory
/uploads # file

Ignoring only Folders and not Files

# .gitignore
uploads/

Result:

# will ignore:
/uploads # directory
/some/path/uploads # directory

# will NOT ignore:
/another/path/uploads # file

Categories
WordPress WordPress Development

This exceeds GitHub’s file size limit of 100MB

Solution for “This exceeds GitHub’s file size limit of 100 MB” issue

git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch YOUR-FILE'
git push