GIT COMMON COMMANDS
DevOps Certification Training
[email protected]
+91-7022374614
US: 1-800-216-8930(Toll Free)
DevOps Certification Course
GIT COMMON COMMANDS
1: git init
You can create a repository using the command git init. Navigate to your project folder and
enter the command git init to initialize a git repository for your project on the local system.
$ git init
2: git status
Once the directory has been initialized you can check the status of the files, whether they are
being tracked by git or not, using the command git status.
$ git status
DevOps Certification Course
3: git add
If we want to track all the files in the project folder, we can type the command,
git add.
$ git add
DevOps Certification Course
4: git commit
Once the files or changes have been staged, we are ready to commit them in our repository.
We can commit the files using the command “git commit –m “custom message”.
$ git commit –m “custom message
5: git remote
Once everything is ready on our local, we can start pushing our changes to the remote
repository. Copy your repository link and paste it in the command git remote add origin “<URL
to repository>”
$ git remote add origin “<URL to repository>”
DevOps Certification Course
6: git push
To push the changes to your repository, enter the command git push origin <branch-name> and hit
enter. In our case the branch is master, hence git push origin master. This command will then prompt
for username and password, enter the values and hit enter.
$ git push origin master
7: git clone
If we want to download the remote repository to our local system, we can use the command git
clone <URL>.
$ git clone <URL>
DevOps Certification Course
8: git pull
The git pull command is also used for pulling the latest changes from the repository, unlike git
clone, this command can only work inside an initialized git repository. This command is used
when you are already working in the cloned repository, and want to pull the latest changes,
that others might have pushed to the remote repository git pull <URL of link>
$ git pull <URL of link>
9: git branch
Until now, we saw how you can work on git. But now imagine, multiple developers working on
the same project or repository. To handle the workspace of multiple developers, we use
branches. To create a branch from an existing branch, we type
git branch <name-of-new-branch>
Similarly, to delete a branch use the command git branch –D <branch name>
$ git branch <name-of-new-branch>
DevOps Certification Course
10: git checkout
To switch to the new branch, we type the command git checkout <branch-name>
$ git checkout <branch-name>
11: git log
Want to check the log for every commit detail in your repository? You can accomplish that
using the command git log
$ git log
DevOps Certification Course
12: git stash
To stash your staged files without committing just type in git stash. If you want to stash your
untracked files as well, type git stash –u. Once you are back and want to retrieve working, type
in git stash pop
$ git stash.
$ git stash –u
$ git stash pop
DevOps Certification Course
13: git revert
git revert <commit-id> command helps you in reverting a commit, to a previous version
$ git revert <commit-id>