Version control (sometimes referred to as source control) plays an important role in any development project, including test automation. It is the practice of tracking and providing control over changes made in the source code. And since one of the most common tools used in version control is Git, let’s get to understand some of the most common Git commands.
Git is a fast, scalable, and distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.
- Initialize current directory as a Git repository.
git init
- Create a local copy of a repository from a hosted location via URL.
git clone URL
- Show a list of modified files in your working directory and whether they are staged for the next commit.
git status
- Add changes from a specific file to the stage, ready for your next commit.
git add file.js
- Add changes from all files to the stage ready for your next commit.
git add .
- Unstage a specific file, while still retaining the changes in the working directory.
git reset file.js
- Unstage all files, while still retaining the changes in the working directory.
git reset
- Display a list of branches with an asterisk(*) next to the active branch
git branch
- Create a new branch
git branch name
- Switch to another branch and check it out into your working directory.
git checkout branch
- Create a new branch and switch to that branch
git checkout -b branch_name
- Commit your staged content as a new commit snapshot with a specified message.
git commit -m "your commit message"
- Fetch all the changes from the remote repository and merge any remote changes in the current local branch.
git pull
These are few basic commands which can help you get started with git easily. Hope you find this article useful.
Thank you.
Top comments (5)
This is a nice list on the basic Git commands.
I have a nice addition for that. I recently experienced with Git Aliases and have to say that they are really awesome and should be know by every Git user!
Because I like them so much I created an article that explain how I use them to delete all my local branches that I do not need anymore:
If you are interested you can read about it here: knulst.de/how-to-remove-local-git-...
If you did not know about Git Alias it's worth reading about!
Thanks for sharing, and making this article useful for every reader.
It already was super useful!!
I am just so happy about Git Alias and want to spread the information :-D. I'm totally into them since 1 week ^^
Thanks for sharing great info
Thanks for compiling this list