Intro
Why Git?
Git is a popular version control system which was created by Linus Torvalds and is used for:
- Tracking code change.
- Track of code editor.
- Easy collaboration.
Getting Started:
Install Git:
For Debian:
For Fedora:
1
|
git config --global user.email "test@test.com"
|
Listing all config:
Initializing git:
Adding New File:
Seeing Status
Commiting change
1
|
git commit -m 'comment'
|
Cloning repo
1
|
git clone http://test.test
|
Pushing to github
or
Git ignore for ignoring files.
Sometimes do don’t want to share some files in a public repo but for testing purpose we need to have those files in the local machine. For this situation we use .gitignore.
First we create a file called .gitignore.
Inside .gitignore file we add the file or folder name to be ignored by git.
1
2
|
touch .gitignore
nano .gitignore
|
Github SSH
-
Creating Key
1
|
ssh-keygen -t rsa -b 4096 -C "test@test.com"
|
-
Adding key in the Github
copy the key generated by ssh-keygen in /home/username/.ssh from the file id_rsa.pub and paste that in the github website account settings -> SSH and GPG keys -> New SSH key -> Add SSH Key
-
Testing Connection
Push an existing repo
1
2
3
|
git branch -m master (Here you are creating a branch called master)
git remote add master git@github.com:xxxx (here master is the remote repo identifier)
git push master (if your branch and remote repo name is same)
|
-
If different identifier name or multiple repo
1
|
git push -u origin main (if you have multiple remote repo. Origin is the repo identifier and main is branch name)
|
Here are some cheats
Cheat 1
Cheat 2
Image credit goes to twitter @Sheraj99