6
20 Git Commands You Should Know
source link: https://www.c-sharpcorner.com/article/20-git-commands-you-should-know/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Introduction
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've made to files in your project. It comes bundled with a large number of commands that you could use to efficiently manage your source code.
In this article, we'll go over the 20 most frequently needed Git commands that every software developer should know.
Check the git configuration
- git config -l
The above command displays a list of information about your git configuration including user name, email, default code editor, etc.
Configure your Git username
- git config --global user.name "harshal"
The above command could be used to configure your git user name. Please make sure to replace your git username with harshal.
Configure your Git email
- git config --global user.email "[email protected]"
The above command could be used to configure your email address. Replace your email address with [email protected].
Initialize a Git Repository
- git init
Add a single file to the staging area
- git add my_file
Add all files to the staging area
- git add .
Check Git status
- git status
Commit changes
- git commit
Commit changes with a message
- git commit -m "Your commit message"
Check Git history
- git log
The above command displays a list of commit logs
Get branch list
- git branch
You could use the above command to display the list of all the created branches in the local repository.
Delete a branch
- git branch -d my_branch
Create a new branch
- git branch my_branch
Switch branches
- git checkout my_branch
Create a new branch in Git and switch to it immediately
- git checkout -b branch_name
Add a remote repository in Git
- git add remote https://repo_url
Push your changes to a remote repo in Git
- git push
Pull changes from a remote repo in Git
- git pull
Stashing changes
- git stash
Reverting stashed changes
- git stash pop
And that's it. These were the 20 Git commands I use the most often.
I hope you found this article useful – Enjoy
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK