Git commands:
Hello friends,
In the previous article, we see some tools to Git. In this article, we will talk about some frequently used Git commands, which are very important.
- git clone:
git clone command used to clone /duplicate remote repository in local machine.
Just copy the URL in the Colne tab, as shown here.
Type git clone then press the right mouse button and paste it.
2. git checkout: It is mostly used to switch the branch.
By using -b as shown, we can create the branch and switch to that branch.
If you already have a branch and want to switch to it then use the checkout as shown in the image.
We can also use checkout to remove modifications on a local machine that are not pushed to the git repository.
3. git status:
With this command, we can see the changes we made in a repository on a local machine.
Here, We can see details of changes we made in the project.
4. git add:
After we make changes in the local machine, to store them in a remote repository we need to use this command to verity those files to store on git. It tells Git that you want to include updates to a particular file in the next commit. However, It doesn't really affect the repository in any significant way changes are not actually recorded until you run the commit command.
i) To add a single file:
git add <file>
ii) To add all files:
git add .
With this, we can add all the changes, and make it ready for commit. after this command we can check it by using, git status
5. git commit -m “ “:
Git commit is like setting a checkpoint in the development process which you can go back to later if needed. We also need to write a short message to explain what we have developed or changed in the source code.
It will save our changes locally to the local git file.
6. git pull origin <branch name>:
If you are working in a team then, before starting your work it is very important to take PULL from the remote repository.
It will help to avoid merge conflicts. Also, it will save other team members as well as your work and efforts.
7. git push origin <branch name>:
Using this command we can save changes added using git add and git commit commands to the remote git repository.
8. git config — global user.name “ “/it config — global user.email “ “
This command used to set your user name and the user email to communicate with repository, it also asks for a password while pushing code to the repo. It's only a one-time process for a repository from the same account.
In case if we have more than one account for git. then we can set user name and email for that repository using,
git config — local user.name ”… “ and git config — local user.email “… “
We need the above commands for more common work like save and store our project to git. There are some advanced commands also to merge branches, going back to other commits, revert back to old commits, etc.