![]() |
| All About Git and GitHub | IndianTechnoEra |
Git
What is GIT?
Git is
software
It can use for the anything web developer, software developer, etc.
It
saves the changes when multiple people work on the same project
It updates
the changes and keeps the previous version.
Git bash is a type of terminal like the Linux command terminal
Install and start Git
Install
Git
Go to the link and download Git
Then simply
install
Start
Git
Start git
Create
folder
Go to the
folder right click
Git bash
A
terminal will appear
Set user
name and email
git
config --global user.name shahnawaz
git
config --global user.email snawaza243@gmail.com
Open VS
code
code
.
Basic Commands
How to
get a repository?
To get
any repository you can use init command or cloning
If cloning all the codes retrieves from the server
How do
init initialize?
Initialize
empty git repository
git
init
List
and show all hidden folders
ls
ls
-lart
Within
.git folder provided some files
Different
status
Untracked
à Unmodified à Modified à Staged
Keep looking at the modified
git
status
Create
empty file
touch
index.html
touch
contact.html
Track all
un-tracking files and put them into staging area
git
add -A
Then after
staging, needs to commit
git
commit -m "your comment"
Checkout: Back to the previous version checkout or recover the changed file code
git
checkout contact.html
All files
matched to previous code version
git
checkout -f
See
what are the commit
git
log
To filter
the git log output or last 1 commit. It will show the edited content
git
log -p -1
Note: Press
Q to get out from the div area
Compare the current and previous version
git
diff
It will
show the comparison of the current and previous (working and staging stages)
To compare
the staging area with the last area commit
git
diff --staged
Auto commit
git
commit -a -m "skipped staging area and fix"
To remove
a file
After adding
and committing myfile.html
git
rm myfile.html //delete totally remove from working directory
and git staging area
git rm --cached myfile.html //
remove from staging area only and keep in storage, not track
Short show
status
git
status -s
M
M myindex.html *
M myname.html
M mycontact.html
* 1M
=modified in staging area and
* 2M =
working tree
Git ignore
If you
don't want to drag some files then create with git ignore
touch
.gitignore //create ignorable file
touch
mylogs.log //create log file
In .gitignore
mylogs.log // all the files in any
related directory with similar name get ignored
/mylogs.log // ignore at only existing
gitignore file directory
*.log // ignore all the
.log file extension
*.cpp// ignore all the .cpp file
extension
Ignorefolder/ // ignore all
the file of ignorefilder dir
Branches
Show branch
git
branch
Create
a copy of the main/master branch
git
branch branch1
git
branch // branch1 * master
Here
branch1 is a child branch of main branch master
Enter into
branch1 branch
git
checkout branch1 //
The
most common operation
git
status // if modified
git
add –a // add modified
git
commit -m "adding a comment" //commit modified
git
status // ok
git
push // pushing on git if setup ok
git
checkout master // enter into master branch
git
checkout branch1 // enter into feature branch
git
commit -a -m "your comment"
To merge the update feature of branch1 with master
git
merge branch1
Create
and enter in the new branch
git
checkout -b branch2
GitHub
What is GitHub?
A repository
hosting site
Remote
repository
Create
a remote repo and push a local repo in remote
Remote a URL
Add
remote add URL as myurl1
get
remote add myurl1 https://githum.om/snawaza243/cpp-basic-to-adv.git
List
all remote
git
remote
Shows
fetch and push URL link and its name
git
remote -v
push
master branch into myurl1
git
push myurl1 master
[if the repo is private then show a fatal error, for that follow the step to take read-write
access
Auto
read write and give access of your GitHub to your local git system
Go to GitHub
profile settings
SSH
and GPG keys
Generate
SSG keys
Generating
a new SSH key and adding it to the ssh-agent
Copy the code
and replace your account email and paste it into your master
git bash (only enter)
It will
generate a mirror key and then need to deploy
Go to GitHub
and in the Adding your SSH key to the ssh-agent
1. Copy eval code
line and paste in the git command
Eval
$(ssh-agent -s)
It will
generate an agent process it (Agent PID)
2. Add
SSH - copy the command from GitHub and run it in git bash
Ssh-add
~/.ssh/id_rsa
Then go
to Checking for existing SSH keys link
Adding
a new SSH key to your GitHub account
1. Copy
clip and past with code in git bash
Cat
~/.ssh/id_rsa.pub
It will
show the content
Copy all
the content of the output
Goto GitHub
SSH
and GPH keys
New
SSH key
Give unique
title
Paste the
copied content
Push git
bash to GitHub repository
Create
a repository in GitHub and copy ssh link
In git
bash
git
remote set-url myurl1
https://githum.com/snawaza243/python-basic-to-adv.git
(paste
link with shit+insert)
git
remote
git
remote -v
git
push -u myurl1 master
Add more branches
Go to
in git bash
git
checkout branch1
git
push -u myurl1 branch1
git
checkout branch2
git push -u myurl1 branch2
