How To Use Git & GitHub
GitHub account creation :
To create your account, you need to go to GitHub’s website and fill out the registration form.
Git installation :
We need to install Git’s tool on our computer.
To configure username & email_id in git :
- Open Git tool & set your username (username of your Github account)
- Next, set your email
To check whether it has configured?
Now you’re ready to start using Git on your computer!
Create New Repository in Github :
- Go to your GitHub website, look in the upper right corner, andclick the + sign and then click “New repository”
- Name the repository, and add a quick description
- Decide whether you want this to be a public or a privaterepository
- Click “Initialize this repository with a README” if you want to include the README file. (I definitely recommend doing this! It’s the first thing people are going to look at when they check out your repository. It’s also a great place to put information that you need to have in order to understand or run the project)
- Click “Create repository”. Your new repository will be created.
- Now you need to get a copy of the repository on your computer. To do that, you need to “clone” the repository on your computer. To clone a repository means that you’re taking a repository that’s on the server and cloning it to your computer, just like downloading it. On the repository page, you need to get the “HTTPS” address 👇
Pushing the code to Github Repo :
1) Go to your project directory using terminal (Git). Use commands as below.
When executing any Git commands, you have to make sure that you are in the correct directory in the terminal.
2) Initialize the local repository now
Now you have a new hidden directory called .git in your project directory. This is where Git stores what it needs so that it can track your project.
3) After converting your directory to a Git repository, the first thing we need to do is to check the files we have by using the following command.
So there are two files in that directory that we need to “add” to our Repo.
4) Add files to the staging area one by one
or add files at once
After the staging area (the add process) is complete, we can check whether the files are successfully added or not by executing the git status. If those particular files are in green like the below picture, you’ve done your work!
5) Then “commit” with a description in it.
6) Give the Github path URL which you have copied from Github
You can check whether remote is added or not
7) Push our project to GitHub
8) To list the version history for the current branch.
9) To list the version history for the current branch in one line.
10) To git log as a graph.
11) To list all the local branches in the current repository.
12) To create a new branch
13) To deleted a branch
14) To switch from one branch to another
15) To create a new branch and also switch to it.
16) To merge the specified branch’s history into the current branch.
17) To checkout a specific commit.
Suppose you have made some changes / added / modified … in your project, to save changes and push to Github, follow these steps:
Cloning existing repo:
- Go Github repo
- Copy repo url by clicking code button
- Open terminal
- Navigate where you want to clone
- Use command:
- then navigate inside clone repo name
NOTE:
- delete local repository
- If you’re working on your computer and want the most up-to-date version of a repository, you’d pull the changes down from GitHub
- Linux basic commands: