As a beginner when you start to learn more about web development, You will be introduced to git which is a version control tool used to monitor and track changes in our files and push our source code to remote depository.
Created by Linus Torvalds, It is a phenomenal tool to use, but becomes very challenging and daunting for newbies at first.
As the terminal spooks out a lot of people, It spooked me out at first, Then I got a grab over it by persisting myself over it.
So this tutorial will help you to get over that fear and will show you the basics of git and how to push your code to your github repository.
Step1:
You need to have a github account first. Create a github account with the below link below.
After creating an account, create a new repository.
Step2:
Now go to git website and download git for windows/mac/linux and install it
Git download website Link : Git
Follow the instructions in the website and download and install for your OS version
After installing check git version with
git --version
in terminal
Step3:
After doing the Above steps, Open the terminal.
Create a directory and index.html file
mkdir folder-name
touch index.html
Now open with vscode in terminal with
code .
Or with atom
atom .
There are two stages in git,
1. Staging area
2. Committing the code
The staging area is there to keep track of all the files which are to be committed.
Files which are not added to the staging area will not be committed.
Now in terminal paste the following code one by one.
git init
git init must always be called in the folder the first time where we wish to include git functionalities and push that folder contents to remote github repositories.
By doing this command we will create a file called .git in that specified folder.
git add .
git add . will add all the files to staging area while
git add index.html
will only add index.html to the staging area.
git commit -m 'committed'
We commit our files with the above command before pushing it to github repo
git status
With git status we can find out information about which files are modified and what files are there in the staging area
Now comes git's most important concept called branching.
A branch is nothing but a pointer to the latest commit in the Git repository. So after committing we create main branch with
git branch -M main
After All these lines of code, we go to vscode/atom and make a change in index.html.Then we again add and commit these files.
git add .
git commit -m "Changed"
This process goes on and on till we are satisfied with our code.
Now we are ready for pushing it to github repo.
After creating the github repo we copy its url and paste it in terminal.
git remote add origin url
Then after that we push it to github with
git push -u origin main
The terminal will ask for github username/email and password so enter that in terminal. It will ask only once after that no need of that
So we have successfully pushed our code to github repo with git.
We can clone/download that remote github repository to our local machine with
git clone url
But these information are just the tip of the iceberg in terms of concepts and usecases for git.
Git has stuff like branch merging, git stash,git checkout,git pull,git log and a lot more advanced stuff.
But the above Code is more than enough for a beginner who tries to understand what's happening in the world of version control.
My Personal Experience
After seeing a lot of youtube videos about git, first it was very daunting for me. Then I divided git into three categories
1. Easy (push to github)
2. Moderate (Making many branches and merging them together)
3. More advanced stuff like git stash and more
I focused on the Easy part of push to github for a week and i mastered it. Then after that it was very easy to learn other stuff like branches. So I can tell you guys have to hang on till the git "Easy" is hammered into your head. That's what I did and got it atlast.
Complete Summary
So below is the complete code required for pushing to git you can copy and paste them one by one and change the url.
git init
git add .
git commit -m "message"
git branch -M main
git remote add origin url
git push -u origin main
To know more about Git & GitHub you can checkout my courses in Udemy.
https://www.udemy.com/course/git-github-for-absolute-beginners/
Top comments (1)
Preciso muito desse tutorial, estou em pânico, tentando enviar o meu arquivo para o git-hub.