Git- my everyday learnings
Remove git init
rm -rf .git
Folder to new repository in Github?
-
Go to said folder & :
git init git add . git commit -m "First commit"
-
Create a new git repository, and don’t add any files in it. No readme nothing, just an empty repo.
git remote add origin remote https://github.com/username/name-of-repository.git git push origin master
That’s it… type in your credentials.
Creating a new git repo and connecting to local
-
Create a new repo on Github
-
Open Terminal
git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
-
Add create files you want
-
And then sync with online repo
git add -A git commit -m "first commit" git push
That’s it… type in your credentials.
.gitignore
Sometimes you might want to add a .gitignore file to ignore certain folders or files:
Create the file in the main folder
touch .gitignore
For ignoring files add *.filetype
. For ignoring folders add
/ignore-this-folder/
followed by git add
, git commit
, git push
(Source, and this). Check your github repo online to see if
the changes are reflected. Mostly not!
So do the following based of of this question: gitignore not working
git rm -rf --cached .
git add .
Changing name of git repository
-
Change name of repository by going to settings on the repo page
-
Change the repo link on the local git cloned folder
git remote set-url origin new_url
Creating a new branch
git checkout master
git checkout -b new_branch master
git push origin new_branch
Going back to older commit
git revert --no-commit oldercommit..HEAD
git commit -m "reverted to oldercommit"
Accidentally uploading a large file commit
You get the dreaded git error from remote saying you tried to commit a large file. In this particular case I had uploaded a file “core” which is genenrated by linux in case of wierd crashes. No worries. this shit can be removed peacefully.
I followed the instructions here as it was a recent commit and I had not done anything after that:
git rm --cached core
git commit --amend -C HEAD
lazygit "comment"
and done. :)
Git local folder to new repo
Refer here regarding installation and PATs
-
create repo (make public or private), should not matter (but not tested on private)
-
git commands
git init git add -A git commit "first commit" git remote set-url origin https://user1@github.com/user1/myRepo1.git git push -u origin main
git large files shabang
manage large files but with traditional way how we ork with git.
Installation of git-lfs
https://packagecloud.io/github/git-lfs/install#bash
curl -s
https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh
| sudo bash
Follwed by,
sudo apt install git-lfs
Initialze and check if git lfs is installed:
git lfs install
To track files in a repo:
git lfs track '*.zip'
Push
git add .
git commit -m "git lfs commit"
git push
This will give error:
error: failed to push some refs to 'https....gitrepo'
try removing .git/hooks/pre-push and then it works as per here.
Check out git lfs tracking
Go to .gitattributes
or type git lfs track
. And git lfs ls-files
to see which files are tracked.