Basic Git Commands
Table of contents
Hello readers, this is the continuation to the previous blog Introduction to Git, for your reference please follow this if you missed the previous blog.
in part - 2 we are going to discuss some more git commands which are commonly use in our day to day work.
Git Commands
To merge the branches:
- branch2 will merge with the branch1
$ git merge branch1 branch2
- To switch to another branch from the current branch, and if the specified branch name does not exist git will create new branch with the specified name:
$ git checkout branch_name
- To revert to the earlier commits.
- To perform this operation commit id is required, we can get commit id from the git log command
$ git revert commit-id
- To record the current state of the working directory and the index, but want to go back to a clean working directory.
- The command saves your local modifications away and reverts the working directory to match the HEAD commit
$ git stash
- To revert back to the working directory with the local modifications which are stashed before:
$ git stash pop
- To list the files in the stash:
$ git stash list
- To delete all the files from the stash:
$ git stash clear
To merge only a specific commit ID from source to target branch:
Scenario:
- Suppose you have two branches named "dev" and "test" .
- Currently you are headed to "dev" branch and wants to merge specific commit of "dev" branch to the "test" branch.
First you need to switch to the "test" branch with the help of "git checkout test" command
From the test branch using the commit id of the "dev" branch and cherry-pick command we can perform the operation.
$ git cherry-pick commit-id
To download commits, files and references from a remote repository into the local repository:
- Gives the information of a new change from a remote repository without merging into the current branch
- Repository data is updated in the .git directory
$ git fetch --all
Subscribe to my newsletter
Read articles from Sreedevi Valeti directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Sreedevi Valeti
Sreedevi Valeti
I am a Tech Enthusiastic, working as a Cloud Engineer. I have expertise in Cloud Administration. Tech Stack: Multi-Cloud: AWS and AZURE Programming Languages: Python Infrastructure As Code: Terraform and Cloud Formation DevOps Tools: Git, GitHub, Docker, Code pipeline, Code Build, Code Deploy, Code Commit. OS: Linux Certifications : AWS Certified Solutions Architect Associate, AZ-900 For technical collaborations, you can drop a mail to sreedevi.devopscloud@gmail.com