20 Git Commands You should know ?

Git is a version control system developed in 2005 by Linus Torvalds (The creator of the Linux kernel) ? It helps you keep track of the code changes you have made to files in your project ? It comes with a large number of commands that you can use to ma…


This content originally appeared on DEV Community and was authored by 1nj3ct0r

Git is a version control system developed in 2005 by Linus Torvalds (The creator of the Linux kernel) ? It helps you keep track of the code changes you have made to files in your project ? It comes with a large number of commands that you can use to manage your source code efficiently

In this article ? we'll go over the 20 most commonly used Git commands that every software developer should know

Checking the Git Configuration ?

git config -l

The above command displays a list of information about your Git configuration ? including username, email, default code editor, etc.

Configure your Git Username ?‍♂️?

git config --global user.email "example@sample.com"

The above command could be used to configure your email address ? Replace your email address with example@sample.com

Initialize a Git Repository ?

git init

The above command can be used to initialize ? That is to create a new Git repository ? It can be used to convert an existing project to a Git repository ? The above command creates a new .git subfolder in your current working directory that contains all the require metadata for the new repository

Adding a single file to the staging area ➕

git add FILE

The above command adds a file to the staging area ? Be sure to replace FILE with the name of the file to be added to the staging area

Adding all files to the staging area ?️

git add .

The above command adds all files to the staging area

Check Git Status ?

git status

The above commands displays the status of the current repository including the current branch, the list of deployed, undeployed, and untracked files, etc.

Maintain Changes ?

git commit

The above command commits the changes to head ? When executed it opens a code editor in the terminal where you can write a commit message

Fix Changes with a Message ✉️

git commit -m "YOUR COMMIT MESSAGE"

This command lets you specify just a short summary for your commit message without opening the code editor ✏️ Replace "YOUR COMMIT MESSAGE" with your own commit summary which describes the changes in your commit

Check Git History ?

git log

The above command displays a list of commit logs

Get Branch List Use ?

git branch

The above command to display the list of all created branches in the local repository

Delete a Branch ?️

git branch -d BRANCH

Use the above command to delete a Git branch ➖ Make sure to replace BRANCH with the name of your own branch ?? Also don't forget to add the -d flag ? It tells Git that you want to delete the specified branch

Create a New Branch ✔️

git branch BRANCH

Use the above command to create a new branch ? One thing we need to keep in mind is that Git does not automatically switch to this branch - you need to do this manually with the checkout command (See #14)

Change Branches ?

git checkout BRANCH

You can use the above command to switch to a newly created branch or to another branch

Create a new branch in Git and switch to it immediately ?

git checkout -b BRANCH

You can create and checkout a new Git branch in a single command by adding the -b option to the checkout command

Adding a Remote Repository in Git ⬆️

git add remote "https://REPO_URL"

The command adds a remote repository to your local repository ? Make sure to replace REPO_URL with the actual URL of the remote and repository

Commit your changes to a remote repository in Git ?

git push

You can use the above command to commit your changes to the remote repository

Pulling Changes from a Remote Repository in Git ?

git pull

You can use the above command to pull the latest changes from the remote repository

Stowing Changes ?

git stash

The stash command allows you to temporarily park (stash) your uncommitted changes (Both staged and unstaged) to save them for later use

Undoing Saved Changes ?

git stash pop

Use the above command to reapply changes parked with the stash command

And that's it ? Those were the 20 Git commands I use most often
I hope you found this article useful - have fun ??

Also Published on C Sharp Corner ?


This content originally appeared on DEV Community and was authored by 1nj3ct0r


Print Share Comment Cite Upload Translate Updates
APA

1nj3ct0r | Sciencx (2021-04-08T18:28:14+00:00) 20 Git Commands You should know ?. Retrieved from https://www.scien.cx/2021/04/08/20-git-commands-you-should-know-%f0%9f%98%8e/

MLA
" » 20 Git Commands You should know ?." 1nj3ct0r | Sciencx - Thursday April 8, 2021, https://www.scien.cx/2021/04/08/20-git-commands-you-should-know-%f0%9f%98%8e/
HARVARD
1nj3ct0r | Sciencx Thursday April 8, 2021 » 20 Git Commands You should know ?., viewed ,<https://www.scien.cx/2021/04/08/20-git-commands-you-should-know-%f0%9f%98%8e/>
VANCOUVER
1nj3ct0r | Sciencx - » 20 Git Commands You should know ?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/08/20-git-commands-you-should-know-%f0%9f%98%8e/
CHICAGO
" » 20 Git Commands You should know ?." 1nj3ct0r | Sciencx - Accessed . https://www.scien.cx/2021/04/08/20-git-commands-you-should-know-%f0%9f%98%8e/
IEEE
" » 20 Git Commands You should know ?." 1nj3ct0r | Sciencx [Online]. Available: https://www.scien.cx/2021/04/08/20-git-commands-you-should-know-%f0%9f%98%8e/. [Accessed: ]
rf:citation
» 20 Git Commands You should know ? | 1nj3ct0r | Sciencx | https://www.scien.cx/2021/04/08/20-git-commands-you-should-know-%f0%9f%98%8e/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.