Skip to content

Git

Git is a distributed version control system for tracking changes in source code during software development. It is designed to be fast, efficient, and easy to use. Git is widely used by developers for projects of all sizes, from small open-source projects to large enterprise applications.

Benefits of using Git

  • Version control: Git allows you to keep track of changes in your code over time. This makes it easy to revert to previous versions of your code if necessary.

  • Branching: Git allows you to create branches of your code. This allows you to experiment with new features without affecting the main codebase.

  • Merging: Git allows you to merge branches of your code. This allows you to integrate changes from different branches into the main codebase.

  • Distributed: Git is a distributed version control system. This means that each developer has a complete copy of the codebase, which makes it easy to collaborate on projects.

Create your Github account

  1. Goto GitHub
  2. Click Sign Up and create your account

Installing Git

Git comes installed in the Linux instances that you create in AWS, but if you are trying to install on your own laptop or desktop, you can follow along based on your operating system. Install Git

Working with GitHub

  1. Login to your GitHub account created earlier
  2. Click New and create a respository myrepo

github

  1. Leave the rest of the details as default
  2. From the command line where the git is installed issue the clone command to get a copy of your repo in your local system
shell
git clone https://github.com/spjohn85/myrepo.git
  1. Create a branch name where your code will be saved
shell
git branch -M main
  1. Create a new file called sample.txt and add some content
shell
echo "Version 1" > sample.txt
  1. In order to send this file to version control system, you use add, commit and push commands
shell
git add .
git commit -m "initial commit"
git push
  1. Goto GitHub account and when you click on the repository you will find this file in branch named main
  2. You can edit the file in your local and push the changes again to see that both the versions of the file are existing in the repository
shell
echo "Version 2" > sample.txt
git add .
git commit -m "changed file"
git push
  1. Thus GitHub helping you in managing the versions of code you write and see what changes has been made and even who made that change.

Essential Git commands

git init: Initializes a new Git repository.

git clone: Clones a Git repository from a remote source.

git add: Adds files to the Git staging area.

git commit: Commits changes to the Git repository.

git status: Shows the status of the Git repository.

git branch: Lists and manages Git branches.

git checkout: Switches between Git branches.

git merge: Merges branches into the main codebase.

git push: Pushes changes to a remote Git repository.

git pull: Pulls changes from a remote Git repository.

Released under the MIT License. Some of the contents are generated using Gen AI