

Steps that can make your workย half!!
First select your project & open your terminal in your projectโs root directory.
git --version
If it is not showing the version of git then go to the official website of git and download the git according to OS of yourย system.
git config --global user.name "Your_Name"
git config --global user.email "Your-Email"
git init
Note:- On your Projectโs root directory
It initializes the git repository in local project & will makeย .git folder that contain important folders andย files.
There are three stepsย :-
Step 1ย : We need to add a file to staging areaย .
git add <File_Name> {{For Single File}}
git add . {{For all the files in current Directory}}
Noteย :- In place of <File_Name> add your file and if you want select all the files in current directory then use {{ย . }} or {{ *ย }}
Staging areaย :- Staging area is that area where we can buy some items and put them in bucketย .
To check,if files are added or not,useย this:
git status
Step 2ย : Commit a file into the git repo is to write a commitย message.
m =ย message
git commit -m "First Commit"
Noteย :- In the โDouble Quotesโ, you should write yourย message.
Step 3ย : Push the file into a remote repository. {{Github}}
Now create your account on git-hub and create a repositoryย .
To add files in your remote repo use thisย :
git remote add origin git@github.com:"Username_on_github"/"Repository_Name"
Noteย :- This above command is a single command & Now place your git-hub username (without any quotes) and put your repository name (without anyย quotes).
Like this
git remote add origin git@github.com:XYZ/project.git
And if you donโt understand this then go to your repository on git-hub and click on clone or download button and copy url with SSHย method.
To check
git remote -v
Why we useย SSH?
By using the ssh protocol, we can connect and authenticate to remote servers and services. With ssh keys we can connect to GitHub without supplying our username and password at each visit with the help of passphrase.
In HTTPS method, you will need to fill our username and password at every visit, which will be very inconvenient.
Git associates a remote URL with a name and our default remote is usually calledย โOriginโ
1. Generating New ssh key and adding it to a sshย agent.
ssh-keygen -t rsa -b 4096 -C "email"
Noteย :- Place your email in โdoubleย quotesโ.
This creates a new ssh key using the provided email as aย label.
1.1. For default file Press {{ ENTERย }}
/home/{{username_of_pc}}/.ssh/id_rsa: ENTER
1.2. Enter a passphrase.
1.3. Now our identification has been savedย in
Private Key : /home/{{username_of_pc}}/.ssh/id_rsa
& Public Key : .ssh/id_rsa.pub
2. Adding our ssh key to the sshย agent
eval "$(ssh-agent -s)"
it gives like {{agent_id : 15800}}
3. Now we add SSH Private key to ssh-agent to our defaultย path.
ssh-add ~/.ssh/id_rsa
4. Adding a new ssh key to your githubย account.
Copy the ssh key to our clipboard.
On Ubuntu
sudo apt-get install xclip
on Manjaro
Open Octopi -> Download Xclip
Xclip-set clip <~/.ssh/id_rsa.pub
2. Manualย Method
Home/.ssh/id_rsa.pub
Open this file and copy your key.
Now goto github.com โขโข Under Profile Photo (Drop Down) โขโข Settings โขโข Use SideBar {{ SSH & GPG Keys }} โขโข Then go to this directory on your computer {{Home/.ssh/id_rsa.pub}}
Open this file and copy yourย key.
Create new SSH key โขโข Title the filed with descriptive label โขโข Paste key into a โKey Fieldโ โขโข Click on {{ Add SSH Keyย }}
5. Now for Testing SSH Connection.
ssh -T git@github.com
After running thisย , it will show this messege on terminal!!
Hi {{ USERNAME }}! You've successfully authenticated but github does not provide shell access.
git pull --rebase origin master
git push origin master
Noteย : Change โmasterโ whatever branch toย push.
Then you can successfully push your file to remote server and you can setup a SSH Connection.
To check the connection
git log
There are concepts that can help you to understand the git moreย deeply.
git checkout -b Branch_name
If you want to switch back to masterย branch.
git checkout master
If you want to delete theย branch.
git branch -d Branch_name
To update local repository to the newestย commit
git pull
To merge another branch in activeย branch.
git merge <branch>
In both cases git tries to auto-merge changes. unfortunately this is not always possible and results are in conflicts.
we can merge those conflicts manually by editing the files shown byย git.
git add <filename>
Before merging changes we canย preview.
git diff <source-branch> <target-branch>
we can give tag (lineย 1.0.0)
git tag 1.0.0 {{1b2eld63ff}}
Noteย : {{ this is the first 10 characters of commit id.ย }}
By Git Log we can study repository history.
Advancedย :
git log --author <name>
2. Very compressed log.
git log --pretty=oneline
More preferable format
git log --pretty=format:"%h - %an, %ar : %s"
3. It will only show the files that haveย changed.
git log --stat
git checkout --filename
(if we did something wrong) then this will replace file with the last content inย HEAD.
If we want to drop all local changes and commits, fetch the latest history fromย server
git fetch origin
git reset --hard origin/master
Gitignore file โขโข Is a file that specifying the files or folders that we want toย ignore.
There are several ways to specifying those
Like this
1. Built in gitย Gui.
gitk
2. Use colorful-git output.
git config color.ui true
3. Use interactive adding.
git add -i
For GitIgnore
Lastly, You are requested to share your views on this article.ย :)
Find something useful? Hold down the ๐ to support and help others find this article. Thanks for reading!!
Follow me on Instagram @hypnosisss___ย :)
Create your free account to unlock your custom reading experience.