GIT and GITHUB Commands

GIT and GITHUB Commands

05 May 2023

Git: It is an open source version control application for tracking and managing code. Linus Torvalds, the man behind Linux, created it. Git can be used on both Windows and Mac operating systems, so you don’t have to be running Linux to use it.

A version control system allows you to keep track of changes to your papers. This allows you to easily recover prior versions of your text if you make a mistake, and it makes cooperation with others much easier.

GitHub: GitHub is a web-based platform for hosting Git repositories. It was created in 2008 and is currently a subsidiary of Microsoft. Many features on GitHub, such as pull requests, issue tracking, and code review tools, make it simple for developers to collaborate on code.

git-and-github-commands-01

How Git and GitHub Work Together

Git and GitHub operate in tandem to make it simple for developers to collaborate on code. After creating a Git repository, a developer can submit their code to GitHub to make it available to others.

Other developers can then clone the repository and make modifications to the code on their local PC. They can then push their changes to GitHub, where the original developer can review them and, if satisfied, merge them into the main repository.

GitHub also has capabilities like pull requests and issue tracking that allow developers to easily collaborate on code and debate changes. Developers can use pull requests to request that their modifications be merged into the main repository, whereas issue tracking allows them to discuss problems with the code and provide remedies.

There are three step to push our code from local repository to remote repository
1. Untracked
2. Staged
3. Push

Terms Related to Git

  • Repository: A repository contains your project folders that are set up for version control.
  • Fork: Copy of a repository.
  • Pull Request: A pull request is the way you request that someone reviews and approves your changes before they become final.
  • Local repository: Our computer has a local repository that holds all the files and directories. When offline, this repository is used to make local modifications, examine the past, and commit.
  • Remote Repository:
    The server repository that could be found anywhere is referred to as the remote repository. Each team member uses this repository to exchange newly created changes.
  • Origin:
    The project from which you clone from is called the origin.
  • SSH:
    The SSH protocol is a method for secure remote login from one computer to another.

Commands

  • Create Repositories

    Git init:
    It is used to create a new repository in our system.

    Git init

    Git config:
    It is used initially to configure the user.name and user.email. This specifies what email id and username will be used from a local repository.

    Git config -global user.name
    Git config -global user.email
  • Make Changes

    Add:
    It helps to move the changes from the working directory to the staging area.
    Git add : use to add the specific file to the
    Git add . : Use to add all the files to the next step.

    Commit:
    It is use to commit all the changes in the next steps
    Git commit :Once this command is run the editor will open to run the comments.
    Git commit -m : It is used to commit the code with the one line comment.

    Reset:
    It undoes changes that you’ve made to the files in your working directory

    Git reset

    Status:
    It is used to check the status of untracked and modified files on the local repository.

    Git status
  • Parallel Development

    Branch:
    It shows all the branches present in the current repository.

    Git branch

    Git branch : It is used to create a branch.

    Git checkout:
    It is used to switch the branch to another branch.
    Git checkout Git checkout -b : It creates a new branch and switches to that branch.

    Merge:
    It is used to combine the changes from one branch to the another branch.

    Git merge
  • Sync Repositories

    Push:
    It is used to push the code to the remote repository.

    Git push

    Pull:
    It is used to fetch all the files from the remote repository to the local repository.

    Git pull
  • Working with Remote Repositories

    Remote:
    It is employed to establish, view, and delete links to other repositories. The connections here are not like direct links into other repositories, but as bookmarks that serve as convenient names to be used as a reference.

    git remote add origin

    Clone:
    It is used to create a local working copy of an existing remote repository. The command causes the machine to download the remote repository. When working with a remote repository, it is comparable to the Git init command.

    git clone
  • Some Advanced Git Commands

    Stash:
    Your updated tracked files are saved using the git stash command on a list of unfinished modifications that you can apply again at any time. A developer can swap branches and work on something else without committing unfinished work by using the git stash command.

    git stash: Keep untracked files alongside your current work.
    git stash pop : Return work that has been stored to the working directory.

    Log:
    It shows the commit history order of a repository. This command helps you understand the state of your current branch by showing you the commits that lead to that state.

    git log

Conclusion

Git and GitHub are critical components of modern software development. They enable developers to collaborate on code, track code changes over time, and make their code available to others. Developers can work more efficiently and effectively with Git and GitHub, resulting in better code and faster development timeframes.

search
Blog Categories
Request a quote