Web Dev

The most used Git commands

The most used Git commands

Git can be very scary in the beginning so knowing the main commands will help getting familiar with this amazing tool.

Before you start playing around with git, you will need to configure it in your computer (if you haven’t done it already).

Configuration

Configure user information for all local repositories:

Sets the name you want attached to your commit transactions

$ git config --global user.name "[name]"

Sets the email you want attached to your commit transactions

$ git config --global user.email "[email address]"

Enables helpful colorization of command line output

$ git config --global color.ui auto

You can initialize a new git repository from your terminal from a specific project folder or create a new project like create-react-app or create-next-app and then initialize git.

Create repositories

Create new repository locally:

$ git init

Staging Modified Files

Prepare the new, modified of deleted file to the commit stage that comes next.

Stage only the specified file.

$ git add [file name]

Stage new and modified files from your working tree to be committed, but it will ignore removed files from your working tree.

$ git add .

Stage new, modified and deleted files, from your working tree.

$ git add -A or --all 

Committing Staged Files

Records file snapshots permanently in version history

$ git commit -m "descriptive message"

Branches

Branches are an important part of working with Git. Any commits you make will be made on the branch you’re currently “checked out” to. Use git status to see which branch that is.

Creates a new branch

$ git branch [branch name]

Switches to the specified branch and updates the working directory

$ git switch [branch name]

Creates and switches to the new branch and updates the working directory

$ git switch -c [branch name]

Combines the specified branch’s history into the current branch. This is usually done in pull requests, but is an important Git operation.

$ git merge [branch]

Deletes the specified branch. This option requires a branch merge to complete this action.

$ git branch -d [branch name]

Forces to delete the specified branch so you don't need to merge branches before deleting the specified branch.

$ git branch -D [branch name]

For more info, check this page below:

https://training.github.com/downloads/github-git-cheat-sheet/

https://git-scm.com/docs

Devzilian

Devzilian

07/21/2022

Leave your comment

Related Posts

Categories