Introduction to git and git commands
Posted By : Aman Verma | 23-May-2022
What is Git ?
Important git commands:
1) Git Clone
2) Git branch
3) Git checkout
4) Git status
5) Git add
6) Git commit
7) Git pull
8) Git push
9) Git revert
1. Git clone :
Git clone command can download source code from a remote repository.
2. Git branch :
Branches are very important in the git . Using branch multiple developers work on the same projects simultaneously. with the help of git branch we can create and delete (Branches).
New Branch -> git branch <branch-name >
View Branch -> git branch
Delete Branch -> git branch -d <branch-name>
3. Git checkout :
This command mostly used for switching from one branch to another branch. We can also use it for check out files.
Ex: git checkout <branch-name
steps follow switch new branch :-
* Firstly you will check your changes in your current branch must be committed or stashed before you switch in to new branch.
shortcut command that allows you to create and switch to a branch at the same time : -
: git checkout -b <branch-name
4. Git status :
Git status command will give all the information about the current branch.
* Current branch is up to date
* Anything to commit, push or pull
* Files are staged, unstaged or untracked
* Files are created, modified or deleted
Ex: git status
5. Git add :
When we will changes in our code like modify , delete and add file ,these changes will show in our local.
Add Single File : git add <File>
Add Everything : git add -A
6. Git commit :
This command use needs to write a short message to explain what we have developed or changed in the source code.
Ex : git commit -m "commit message"
7. Git pull :
This command is used to get updates from the remote repositories.
Ex : git pull <remote-repo>
8. Git push :
This command is used for when you will commit all your changes to the remote server . It will push your file in to remote repository.
Ex : git push <remote-repo> <branch-name>
Ex : git push origin <branch-name>
9. Git revert :
we can undo our commits is by using git revert command. If you want to see our history you can use
git log --oneline
If we want to undo our changes we will use commit_id
Ex : git revert
After this, you will see like this ..
Git revert command can undo the given commit, however can produce a replacement commit while not deleting the older one.