Getting started with Git and creating your first GitHub Repository
From creating your first repository to pushing your project in it.
As you are here, you might know what GitHub is still giving a quick summary.
Github is a collaborative platform for developers, it enables us to work together and contribute to other's projects as well. It enables us to make repositories, commits, create branches and pull requests. But for beginners sometimes it becomes tough to set up Git bash and create their repositories, so I thought to create a blog about how they can set up bash, create repositories, and start pushing their code.
1. Intro and installation of Git
Intro about Git is that it is a version control system software for tracking the changes in source code throughout the development process, we're going to use it for pushing our code to Github and tracking the changes. The basic difference between Git and GitHub is that Git is software and Github is a service.
Use the given link to install Git. Link -> https://git-scm.com/
2. Set up Git
A command-line interface will appear when you open your Git Bash. Now it's time to configure your git with your GitHub credentials.
git config --global user.name "github_username"
git config --global user.email "email_address"
Note: Replace github_username and email_address with your GitHub credentials.
3. Create GitHub repository
Click on New repository for creating one.
Now enter your repository name, provide a description if you want and click create repository in green box.
4. Locate your project folder
Now visit your project folder -> right-click -> show more option -> open Git Bash here.
A command-line terminal like this will appear.
5. Now follow the following commands in terminal.
Initialize the Git Repository
git init
Note: if you already have an initialized Git repository, you can skip this command
Add the files to Git index
git add .
The git add command is used to tell git which files to include in a commit, and the . argument means “include all”. you can replace . with specific file name.
Commit Added Files
When all the files are added git commit command is used to create a new commit.
git commit -m 'my first commit'
-m 'my first commit' is the message that will be added alongside the commit for future help to understand the commit.
Select the branch as main
git branch -M main
Add new remote origin GitHub
Copy the unique link provided by Github and add it to the given below command after origin replacing current written address.
git remote add origin https://github.com/ashish12501/Repositopry-Name.git
Note: Don’t forget to replace the grey coloured part above with your username and repo name.
Push to GitHub
git push -u origin main
With this final command you have successfully pushed your project to github repository. It will take a few seconds depending upon network speed to show changes in GitHub account.
I myself use the same method to push all my projects to github hope it helped you too.
That’s all for this blog. Hope it was useful to you. Leave a comment below to let me know how it went and if it helped you anyhow. It will make me appreciate writing more. Take care :)