An Intro to Git and GitHub

An Intro to Git and GitHub

Git :

Git has become an industry standard for development. Being able to snapshot your code at a specific time is incredibly helpful as your codebase grows and you have to reference previous versions of it.

It is a free and open-source distributed version control system. Version control systems allow you to record changes to files over time, thus, you can view specific versions of those files later on.

Sign-up and Installation Process :

Go to GitHub.com and signup puts some basic details and verifies your email id then install git( https://git-scm.com/downloads ) download and install in your local system and get ready for the config process.

Go to your GitHub profile and copy the username.

Now go to your terminal and introduce yourself to Git! To set your username.

git config --global user.name "<your_name_here>"

Example : 
git config --global user.name "SM8UTI"

Then config the email address in git.

git config --global user.email "<your_email@email.com>"

Example : 
git config --global user.email "sm8uti@gmail.com"

Now you are ready to use your git on your system.

To get started, you can create a new repository on the GitHub website or perform a git init to create a new repository from your project directory.

The repository consists of three ‘trees.’ First is the working directory, which holds the actual files. The second one is the index or the staging area. Then there’s the head, which points to the last commit you made.

Git Commands :

  1. Git init : Create an empty Git repository or reinitialize an existing one.

    This command creates an empty Git repository - basically a .git directory with subdirectories for objects, refs/heads, refs/tags, and template files. An initial branch without any commits will be created (see the --initial-branch option below for its name).

    git init
    
  2. git clone : creates a local copy of a project that already exists remotely. The clone includes all the project’s files, history, and branches.

    git clone
    
  3. git add : stages a change. Git tracks changes to a developer’s code base, but it’s necessary to stage and take a snapshot of the changes to include them in the project’s history. This command performs staging, the first part of that two-step process. Any changes that are staged will become a part of the next snapshot and a part of the project’s history. Staging and committing separately gives developers complete control over the history of their project without changing how they code and work.

    git add
    
  4. git commit : saves the snapshot to the project history and completes the change-tracking process. In short, a commit functions like taking a photo. Anything that’s been staged with git add will become a part of the snapshot with git commit.

    git commit -m "commit name"
    
  5. git status : shows the status of changes as untracked, modified, or staged.

    git status
    
  6. git branch shows the branches being worked on locally.

    git branch
    
    • Create a new branch : git branch "branch name"

    • Delete a branch : git branch -d "branch name"

    • Force Delete a branch : git branch -D "branch name"

    • Rename a branch : git branch -m "new branch name"

    • List all remote branches: git branch -a

  1. git merge merges lines of development together. This command is typically used to combine changes made on two distinct branches. For example, a developer would merge when they want to combine changes from a feature branch into the master branch for deployment.

  2. git pull updates the local line of development with updates from its remote counterpart. Developers use this command if a teammate has made commits to a branch on a remote, and they would like to reflect those changes in their local environment.

  3. git push updates the remote repository with any commits made locally to a branch.

Did you find this article valuable?

Support Smruti Ranjan Nayak by becoming a sponsor. Any amount is appreciated!