Git is a free and open-source version control system.
- Git helps developers track code changes, work together easily, and go back to previous versions if needed.
- It allows multiple people to work on different features at the same time.
- Git also keeps code safe and helps with automation, making software development faster, easier, and more organized.
- Tracks Changes โ Git saves different versions of your code, so you can go back if needed.
- Works Offline โ You donโt need the internet to use Git on your computer.
- Team Collaboration โ Many people can work on the same project without messing up each otherโs code.
- Branching โ You can create separate branches to test new features without affecting the main code.
- Safe & Fast โ Git keeps your code safe and makes software development quick and organized.
In a simple word, if you are not initiaizing git in you system using git init command you can clone the repo using command.The .git folder will created in the folder where you are cloning the repo.
git clone <https://rep-you-want-to-clone>Initilize the git -This command will initlize the git repo inside your system folder
git initCheck status -This command will check the status in which branch you are now. How many file changed and added.
git statusCommand to create new branch from base branch
git switch -c <new_branch_name>
git checkout -b <new_branch_name>Commands to add or load the changes into repository
- git add . OR git add -A OR git add * : To add all the file that is appearing in changes
- git add <particular_file_name> : To add particular file from changes appear in changes.
git add .
git add file_name_1, file_name_2
git add *
git add -ACommand to unstages
git reset
git restore <file_name>Command to commit the changes to the repository
amend is use for overwrite the earlier commit message or with --no-edit to update in earlier commit.
git commit -m "Your_Message_That will_Show_In_Commit_Section"
git commit --amend --no-edit
git commit --amend -m "New commit message" -After the amend command you have to do --force if you have pushed the commit earlier.
Command to push the changes to the repository
git push -u origin <branch_name>
git push --set-upstrem origin <branch_name>Command to delete the branch
git branch -D <branch_name>
git branch -d <branch_name> // Delete the branch from remote as wellCommand to update working branch with base branch
git switch <name_of_base_branch>
git pull
git switch <working_branch>
git merge <name_of_base_branch>Commands to revert the commit
git reset --soft HEAD ~n //To keep the changes
git reset --hard HEAD ~n //To delete the changes do not want to keep it.*Command to see all the commit
git log --oneline
git log
git log --oneline --graph --decorate --all // To see in graphical viewCommand to see all history in graphical view
gitk --all
tig --all
-------------------------------
UBANTU : sudo apt install tig |
MAC : brew install tig |
------------------------------ Command to apply one or two commits in one branch from another branch
git log --oneline
a1b2c3d //commit 1
d4e5f6g //commit 2
git cherry-pick a1b2c3dIf you are trying to push the changes to the repository and you are getting error like below, try this command
git pull --rebase
[After that do]
git push
[If getting merge conflict resolve it and then]
git rebase --continue
git push