Welcome to my blog again. In this post, I am going to write about some of the very important Git Commands.
So, before we start with Git Commands, it is important to understand how it is different from GitHub.
While Git is a command line tool, GitHub provides a Web-based graphical interface. GitHub provides hosting for software development version control using Git. It is a subsidiary of Microsoft.
How to get started with Git Commands?
Git Commands to set username and email
It is important to configure your Git username and email address, since every Git commit will use this information to identify you as the author.
On your Git Bash,type the following command:-
- git config –global user.name “YOURUSERNAME” (To add your username)
- git config –global user.email “firstname.lastname@example.org”
(to add your email address)
Git Commands to Clone a repository
Clone via HTTPS:
git clone https://gitlab.com/gitlab-org/gitlab-ce.git (git clone repositorypath)
Clone via SSH:
git clone email@example.com:gitlab-org/gitlab-ce.git (git clone repositorypath)
Git Commands to Push a Code
git branchname (create new brachname)
git checkout branchname(To switch the branch that you have created)
git status (To check the status of your changes)
git add FILE OR FOLDER (when you want to add only specific file or folder)
git add . (To add and commit all local changes)
git commit -m “COMMENT TO DESCRIBE THE COMMIT” (Commit your changes).
git push origin branchname (To push all local commits to your branch that you created)