Basic Git Commands

To use Git, developers use specific commands to copy, create, change, and combine code.
These commands can be executed directly from the command line or by using an application
like GitHub Desktop. Here are some common commands for using Git:

git init initializes a brand-new Git repository and begins tracking an existing
directory. It adds a hidden subfolder within the existing directory that houses the
internal data structure required for version control.

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 checkout is a Git command that allows you to switch between different
branches in your local repository.

git add stages a change. 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 commit saves the snapshot to the project history and completes the change
tracking process. In short, 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 status shows the status of changes as untracked, modified, or staged.

git branch shows the branches being worked on locally.

git fetch is a Git command that downloads the latest changes from a remote
repository to your local repository without modifying your working directory or
your local branch. It updates your local copy of the remote repository’s
branch(es) and downloads new commits, branches, and tags from the remote
repository. You can review the changes before merging them using the git log
command. Once you have reviewed the changes, you can merge them into your
local branch using the git merge command.

git merge merges lines of development together. This command is typically used
to combine changes made on two distinct branches.

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

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

Leave a comment

Your email address will not be published. Required fields are marked *