4. Git checkout<\/strong><\/h2>\n\n\n\nThe git checkout command allows us to swap between current branches or create and switch to new ones. To accomplish this, the branch you wish to switch to must be present in your local system, and any modifications in your current branch must be committed or stashed before making the transition. You can also use this command to verify the files.<\/p>\n\n\n\n
Usage<\/strong><\/p>\n\n\n\nSwitch to an existing branch:<\/p>\n\n\n\n
git checkout <branch-name><\/strong><\/p>\n\n\n\nCreate and switch to a new branch:<\/p>\n\n\n\n
git checkout -b <new-branch-name><\/strong><\/p>\n\n\n\n5. Git\u00a0status<\/strong><\/h2>\n\n\n\nThe Git status command provides all relevant information about the current branch.<\/p>\n\n\n\n
git status<\/strong><\/code><\/p>\n\n\n\nWe can collect information such as:<\/p>\n\n\n\n
\n- Is the current branch up to date?<\/li>\n\n\n\n
- Is there anything to commit, push, or pull?<\/li>\n\n\n\n
- Whether the files are staged, unstaged, or untracked.<\/li>\n\n\n\n
- Whether any files are created, changed, or removed.<\/li>\n<\/ul>\n\n\n\n
<\/figure>\n\n\n\n<\/p>\n\n\n\n
6. Git\u00a0add<\/strong><\/h2>\n\n\n\nWhen we create, modify or delete a file, these changes will happen in our local and won’t be included in the next commit (unless we change the configurations).<\/p>\n\n\n\n
We need to use the git add command to include the changes of a file(s) into our next commit.<\/p>\n\n\n\n
To Add a single file:<\/p>\n\n\n\n
git add <file><\/strong><\/code><\/p>\n\n\n\nTo Add everything at once:<\/p>\n\n\n\n
git add -A<\/strong><\/code><\/p>\n\n\n\nWhen you look at the screenshot above in the fourth area, you’ll notice that there are red file names, which signifies they’re unstaged files. Unstaged files will not be included in your commits.<\/p>\n\n\n\n
<\/figure>\n\n\n\n<\/p>\n\n\n\n
7. Git\u00a0push<\/strong><\/h2>\n\n\n\nAfter you’ve committed your modifications, you’ll want to transmit them to the remote server. Git push transfers your commits to a remote repository.<\/p>\n\n\n\n
git push <remote> <branch-name><\/strong><\/code><\/p>\n\n\n\nHowever, if your branch is just formed, you must upload it using the following command:<\/p>\n\n\n\n
git push --set-upstream <remote> <name-of-your-branch><\/strong><\/code><\/p>\n\n\n\n8. Git\u00a0pull<\/strong><\/h2>\n\n\n\nThe git pull command is used to retrieve updates from a remote repository. This command is a combination of git fetch and git merge, which means that when we use git pull, it retrieves updates from the remote repository (git fetch) and immediately applies the most recent changes to your local repository (git merge).<\/p>\n\n\n\n
git pull <remote><\/strong><\/code><\/p>\n\n\n\n9. Git\u00a0revert<\/strong><\/h2>\n\n\n\nSometimes we have to undo the changes we’ve made. There are several ways to undo our modifications, both locally and remotely (depending on our needs), but we must use these commands with caution to avoid accidental deletion.<\/p>\n\n\n\n
The safer approach to undo our commits is to use git revert<\/strong>. To view our commit history, execute the following command: git log–oneline.<\/strong><\/p>\n\n\n\n
<\/figure>\n\n\n\n<\/p>\n\n\n\n
Then we just specify the hash code next to our commit that we want to undo:<\/p>\n\n\n\n
git revert 3321844<\/strong><\/code><\/pre>\n\n\n\nAfter that, you will see the screen shown below; <\/p>\n\n\n\n
simply hit shift + q to exit:<\/strong><\/p>\n\n\n\n
<\/figure>\n\n\n\n<\/p>\n\n\n\n
The Git revert command will undo the supplied commit, however, it will produce a new one without deleting the previous one:<\/p>\n\n\n\n
The advantage of using git revert is that it does not change the commit history. This means you can still see all of your commits, including those that have been reverted.<\/p>\n\n\n\n
Another safeguard is that everything happens on our local system unless we push it to the remote repository. That is why git reverse is the safer and preferred method for undoing our commits.<\/p>\n\n\n\n
10. Git\u00a0merge<\/strong><\/h2>\n\n\n\nWhen you’ve finished developing your branch and everything is working properly, merge it with the parent branch (dev or master). This is accomplished with the git merge<\/strong> command.<\/p>\n\n\n\nGit merge basically merges your feature branch and all of its commits back into the development (or master) branch. It’s vital to remember that you must first be on the branch you want to combine into your feature branch.<\/p>\n\n\n\n
For example, if you wish to combine your feature branch with the development branch:<\/p>\n\n\n\n
\u00a0switch to the dev branch:<\/p>\n\n\n\n
git checkout dev<\/strong><\/p>\n\n\n\nUpdate local branch of dev:<\/p>\n\n\n\n
git fetch<\/strong><\/code><\/pre>\n\n\n\nMerge feature branch to dev:<\/p>\n\n\n\n
git merge <branch-name><\/strong><\/code><\/pre>\n\n\n\nBefore merging your branches, ensure that your development branch has the most recent version; otherwise, you may encounter conflicts or other issues.<\/p>\n\n\n\n
List Of 50 Basic Git Commands You Should Know\u00a0<\/h2>\n\n\n\n\n\n\n \n \n