DEV Community

Cover image for Basics of Version Control with Git
sdbarlow
sdbarlow

Posted on

Basics of Version Control with Git

Git and GitHub are powerful tools for managing and collaborating on code. In this blog post, I’ll go over the basics of Git and GitHub, including some essential commands you need to know.

Git is a version control system that allows you to track changes to your code over time. It makes it easy to collaborate with others and keep track of changes. GitHub is a web-based platform that provides hosting for Git repositories and allows for easy collaboration on code. Now, let's dive into some of the essential Git commands you should know.

  • git init: This command is used to create a new Git repository in your project directory. When you run git init, Git will create a new .git directory that will store all of the version control data.

  • git add: Use this command to add your changes to the staging area. The staging area is a place where you can review and prepare your changes before committing them.

  • git commit -m "": Once you have added your changes to the staging area, you can use git commit to permanently save those changes to the repository. The -m flag is used to add a commit message that describes the changes you’ve made.

  • git log: This command is used to view a list of all the commits that have been made to the repository. It displays the commit hash, commit message, and other information related to the commit.

  • git remote add origin : Use this command to connect your local repository to a remote repository on GitHub. The remote repository is where you’ll push your changes to and pull changes from.

  • git push: Once you’ve committed your changes locally, you can use git push to send those changes to the remote repository on GitHub.

  • git checkout -b : Use this command to create a new branch and switch to that branch. Branches are used to isolate changes and allow multiple people to work on different parts of the code simultaneously.

  • git pull: Use this command to fetch the latest changes from the remote repository and merge them into your local repository. This is useful when you’re working with others and need to make sure you have the latest version of the code.

These are just a few of the essential Git commands you should know when working with Git and GitHub. As you become more familiar with these tools, you’ll likely discover additional commands that are useful for your workflow. Happy coding!

Top comments (1)

Collapse
 
ant_f_dev profile image
Anthony Fung • Edited

In addition to learning these, I'd recommend getting Git Extensions. It might not look like the slickest client, but it's solid, reliable, and free.