Basic GIT commands line tutorial-for beginners and for developers with examples-computer science/Information technology
GIT Commands tutorial
->Watch this for FUN - Funny job interview
Are you getting bored with online lectures?
->Watch this - When online lectures are boring
Hello Everyone and welcome back to learn one of the most wanted skills in today's world i.e. GIT.
Now we'll gonna start with the basic git commands tutorial.
So, let's get started.
<><><><><><><><><>
First of all, what is git?Git is a free and open-source distributed version control system designed to handle everything from small to very large projects.
Its command-line provides various operations to perform the various tasks of any project. Almost every online project in this world is built with the help of git and its command line.
By learning git you can expose yourself to the current and fastest-growing market skills.
It is the skill that every developer should have, to sustain and grow with the current tech market.
<><><><><><><><><>
Installation of the git:Although there are various ways to work with the git, this section would show you the simple steps to get it installed in a few seconds if the network connectivity is at its best.
Step 1.Go to https://desktop.github.com/ for downloading GitHub on your desktop.
Step 2. Once you are done with the installation, now you can work with git, clone any repository, make a pull request, pull the changes, or push the changes, these can happen with the help of Graphical user interface too but the main motive to work with git is to do all these things with the help of its command-line interface.
Remember this installation is only for you to know the changes made in the repository that you have cloned or view the commits that have been made so far without going to google and view them.
The terminal or the bash is yet to be installed which is our 3rd step.
Step 3. Go to https://git-scm.com/downloads for installation of the git bash and do the necessary set-up and now you must be curious to learn the basic commands used for executing the necessary stuff on the command line.
<><><><><><><><><>
1. Git --version
This command is used to check the version of the git on your computer.
************
2. Git initThis command is used for initializing your working directory.
************
3. Git cloneThis command of git is used to clone the repository into your local system.
The format of it goes here :
git clone name of the repository
The idea of cloning is to copy the source code into your local computer.
************
4. Git remote -vThis command is used for checking the current remote repository on which you are.
************
5. Git addThis command is used to add files in your working directory into the staging area to be committed to your repository.
************
Staging area :Working directory>>>>git add>>>>staging area>>>>git commit>>>>repository
************
It can be done using the following two commands :(a.) git add the name of the files
Well, this command becomes quite inefficient when there are a lot of files to be added to the staging area. Hence to avoid this we use,
(b.) git add .
This (.) that we use adds all the files in the working repository to the staging area.
************
6. Git commitThis command should be used when you are committing anything to the remote repository after adding to the staging area.
The syntax for it is:
git commit -m "a message"
Well, this -m shows the message to be given as to be there with the commit.
************
7. Git pushThis command is used to push the changes to the current repository.
The syntax goes as follows:
git push/git push origin master
In case if the above doesn't work out then run:
git push -f origin master to force the changes.
************
This command is for checking the status of the current repository. It tells you about the current status of the files which are committed, on which repository you are, etc.
Run git status for above.
************
9. Git pullRun this command to pull the changes made in the repository. You can also run
git pull origin master/git pull -f origin master
************
10. Git commit -aWell, this command is used for staging the files, the files which are modified or deleted, but the other files are untouched.
Run git commit -a for above.
************
11. Git branchThis command is for checking the branches available for that repository.
(a.) Run git branch for above.
(b.) Run git branch name of the branch to create a new branch (locally).
(c.) Run git push --set -upstream origin branch name to create a new branch (globally).
(d.) Run git checkout name of the branch to switch to the branch.
(e.) Run git checkout -b name of the branch to directly switch as soon as a new branch is created.
(f.) Run git push origin --delete name of the branch to delete the branch globally.
(g.) Run git branch -d name of the branch to delete the branch locally.
************
12. Git stashIt should be in use when let's say you are working on a file for which you want to commit the changes later on after working on some other repository hence with this command you can stage your file so that it would be accessed later on.
For this run:
git stash ( after git add name of the file )
If you want to save your stash file with a message then run:
git stash save "a message"
For accessing the file again, use:
git stash pop / git stash apply the first few characters of commit hash
Commit hash is nothing but a unique ID associated with the commit.
Run git stash list / git stash show for viewing the files in the staging area.
************
13. Git logThis command is used for checking the history of commits.
Run git log --oneline for checking all the commits.
Run git log --before="date" for accessing the commits before a specific date (format of date would be shown by running git log --oneline).
Run git log --after="date" for after that specific date.
Run git log --author="name of the author" for accessing the commits from a particular author.
************
14. Git rebaseRun git rebase branch name this command to ensure that whatever you are working and modifying would store somewhere else so that you can again access it.
************
15. Git configWell this command is to configure the user's information like it's name and email.
The format goes :
Run git config --list --show-origin for viewing your settings.
Run git config --global user.name " Your name " for changing your name.
Run git config --global user.email " emailid@gmail.com " for changing your e-mail.
************
16. Git remote set-urlThis command is used for setting the remote repository.
Run git remote set-url origin name of the repository/git remote add origin name of the repository
************
17. Git mergeThis command is used for merging the other branch into the current branch.
Run git merge branch name
************
18. Git revertThis command is to revert to the previous changes.
Run git revert the first few characters of commit hash (which is already explained above)
If you want to revert the changes made in the file back after reverting, then run:
git revert HEAD
************
19. Git resetThis command is to reset the committed changes back.
Run git reset --hard HEAD for going back to previous commits before HEAD by deleting the un-committed changes.
Run git reset --soft HEAD for going back to previous commits without touching the staged files.
************
20. Git fetchThis command is used for downloading the commits and all the files from the remote repository.
The command goes like:
git fetch remote-repository-url
************
21. Git diffThis command is used for checking the differences which are not yet staged.
************
22. Git rmThis command is used for deleting any file/folder in the working directory.
The command goes like:
git rm name of the file/folder
Are you getting bored with online lectures?
Watch this - When online lectures are boring
Hope you have learned
something new
today.
Visit other posts by clicking
on LABELS for
learning
more.
more.
<><><><><><><><><>
Please do follow
and comment
and comment
and don't
forget
to
SUBSCRIBE.
<><><><><><><><><>
Informative
ReplyDeleteThanks for sharing the valuable information here. Keep sharing more informative articles.
ReplyDeleteUAS
UAV
4607
4609
4586