Important Git Commands for Beginners You Should Know

Git Commands for Beginners: Git is free and open-source software distributed under the ( GNU ) General Public License that is used to coordinate and control the development of software projects and it’s also known as source control because of its ability to save changes made to files. when changes are made locally, they are committed and then send to the repository within git. other developers can clone or pull and from the repository to get the update changes. Here is a full git commands tutorial for beginners

Basic Git Commands for Beginners With Examples

Here is a list of git basic commands to get you started.

git config username

Action:  To set the username and email in the configuration file.Usage: To check your credentials enter the following commands

git config --global user.email

to set your email or username run the below commands

git config --global email="example@mail.com"
git config --global username="my_username"

git init repo

Action: to initialize a git repository for a new or existing project.Usage: run the following command in the root of the directory of your project.

git init

git clone branch

Action: Copy a git repository from a remote source.Usage: The following code will clone an existing project from the repository to the local directory.

git clone <git url>

git status

Action: To check the status of files you have made changes to.usage: List all files that have changed in your working directory.

git status

git add all

Action: Add changes to stage in your working directory usage: you can add a specific file by specifying the file name after this command, but it is better you use the below command to add every changed file in your working directory.

 

git add < file name>

or add everything in the current directory.

git add .

git commit message

Action: Commit your changes and set it to a new commit object for your remote.

git commit -m "my first commit"

git pull request

Action: pull the update changes from the remote repository.if your remote has updated changes pull them using the following command.

git pull

git branch

Action: Check your current branch

git branch

 git branch -a

Action: list all available branch

git branch -a

git stash

Action: save changes that you do not want to commit immediately. git stash apply if you want to bring your save changes back

git stash

git command to merge two branches

Merge two branches in your local repository into Git-The first line changes the current branch to the “master” branch

Action: merge two branches you were working on.

git merge <branch to merge>

 git remote command

Action:  check what remote or source you have or add a new remote.

git remote

Git Command To Delete Remote Branch

The git branch command cannot be used to remove a remote branch. Instead, use the git push command with –delete flag, followed by the name of the branch you want to delete.

Action:  to delete a remote Branch Use:

git push --delete


Git Commands With Examples

It’s intimidating to use Git from the command line. This collection of popular Git commands, their meanings, and how to use them is here to assist you. We want to make it simpler for people to utilize Git on a regular basis.

Git offers a plethora of useful clients that make it possible to work with the repository without having to use the command line. Understanding how Git works require knowing what the client is doing in the background. We’ve made a list of all the git command that every beginner needs here are they:

  • git config
  • git push 
  • git commit


git command to push to remote

Action:  to delete a remote Branch Use:

git push origin <name of your branch>

git command to switch branch

git checkout <name of your branch>

git commands cheat sheet

If you are looking for a git sheet, download it here.

 

swagasoft

Fully stack(MEAN) software engineer with over five years of experience participating in the complete product development lifecycle of successfully launched applications. Eager and willing to deliver mission- critical technology solutions.

View all posts by swagasoft →

Leave a Reply

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