How to Use Git for Version Control in Web Development

Web development is a wild world where anything can happen. It’s constantly evolving and requires a great deal of attention to keep up with the pace of change. Version control is a crucial part of the process that helps developers keep track of changes and updates. Git is one of the most popular version control systems in the web development world. In this blog, we will explore the basics of Git and learn how to use Git for version control in web development. So, buckle up and let’s take this wild ride together!

Why Do We Need Git?

Have you ever felt lost in the jungle of code changes? That’s where version control comes into play. Git offers a plethora of benefits for web developers, including easy collaboration, rollback, history tracking, and backups. It’s like a survival kit for web developers, ensuring they don’t get lost in the wilderness of code changes.

How to Setup Git in a Local Computer

Installing Git is not rocket science. For Windows users, you just need to go to the Git website and download the installer. For Mac users, you need to use the below command to install git on your mac.

brew install gitCode language: Bash (bash)

To successfully verify the installation of git on both Windows & Mac alike you can run the command

git --version Code language: Bash (bash)

to check if git is properly installed on your computer.

How to Setup Your Name and Email on Your Local Computer

Setting up your name and email in Git is like wearing a nametag in a crowded conference. It helps to identify who made the changes to the code. So, don’t forget to set your name and email in Git, or else you might get lost in the crowd!

You can use the below commands to setup your name and the email address. This is one-time thing, you don’t have to do this while creating a new repository

git config --global user.name "your name" 

git config --global user.email "your email"Code language: Bash (bash)

How to Create a Local Repo

Creating a local repository in Git is like building a shelter in the wilderness. It’s essential to keep track of changes made to the code, and it provides a safe place to store your code. It’s like a hideout for developers to retreat to if things go wrong.

To create a local repository in git, you would have to create a new folder, and make sure to open the go to the particular folder using the terminal and type

git init Code language: Bash (bash)

to initialize an empty git repository.

How to Stage your Files and Commit Them

Staging files in Git is like setting up traps in the jungle to catch animals. It helps to identify which files to include in the commit, making it easier to keep track of changes. Committing files is like hunting and gathering food in the jungle, ensuring you have enough resources to survive.

git add . Code language: Bash (bash)

The git add . command will stage all the files in your repository, so that now they are tracked by git, you can commit them to create a snapshot and save it to git as a version. To create a snapshot you have to type

git commit -m "Your commit message"Code language: Bash (bash)

This will create a snapshot in git. To view all the commits you’ve made so far, you can type

git log --oneline

Creating a GitHub Repo

Creating a repository on GitHub is like starting a fire in the jungle. It provides a platform for developers to share their code and collaborate with others. It’s like sending a smoke signal to other developers, indicating that you’re ready to work together.

  1. Visit https://github.com
  2. Sign up for an account if you haven’t
  3. Create on the + icon at the top right of the navigation bar and click new repository
  4. Give your repository a cool name and click on create
  5. Now copy the link of the repository in the URL bar of the browser.

How to Connect Your Repo to GitHub

Connecting your local repository to GitHub is like building a bridge in the jungle. It connects your local repository to the remote repository on GitHub, allowing you to push your changes to the remote repository. It’s like building a network of bridges that help you navigate the jungle with ease. Type the command

git remote add origin <your github repo url>Code language: Bash (bash)

Pushing Changes to the GitHub Repo

Pushing changes to the remote repository on GitHub is like sending a message in a bottle. It’s a way to share your code with other developers and make it accessible to everyone. It’s like throwing a bottle into the sea, hoping that someone will find it and use your code. When you attempt to run this command, if you’re doing this for the first time, you would be prompted to fill the credentials of your GitHub to authenticate your local git session.
You would have to enter the username and the password to authenticate yourself. (You don’t have to do this every time you want to push code, this is a one time process). Once done. your code should be successfully pushed to your GitHub Repository.

git push -u origin masterCode language: Bash (bash)

Now, you can check your GitHub repository in the browser by reloading, you should now be able to see your local files in GitHub.

In the jungle of web development, Git is a valuable tool that helps developers survive and thrive. It offers benefits such as collaboration, rollback, history tracking, and backups, making it an essential part of the process. And don’t forget to check out the Git Masterclass course on codedamn.com for more guidance and training on Git. Remember, the jungle is full of surprises, and you never know what you might come across. But with Git, you can ensure that you’re always prepared for any changes or updates that come your way.

So, if you’re ready to take on the wild world of web development, make sure to master Git. It’s a valuable tool that will help you navigate the jungle of code changes with ease. And with the Git Masterclass course on codedamn, you can get the training and guidance you need to become a true Git master. So, let’s continue to explore the jungle of web development with Git as our trusty guide!

Sharing is caring

Did you like what Mehul Mohan wrote? Thank them for their work by sharing it on social media.

0/10000

No comments so far