0% found this document useful (0 votes)
2 views

Common-Git-Commands

The document provides an overview of common Git commands used for various tasks such as creating repositories, making changes, syncing repositories, and parallel development. Key commands include 'git init' for initializing a repository, 'git add' for staging files, 'git commit' for committing changes, and 'git push' for pushing changes to a remote repository. Additional commands like 'git clone', 'git pull', 'git branch', and 'git stash' are also explained to manage collaborative development effectively.

Uploaded by

Shivanand Poosa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Common-Git-Commands

The document provides an overview of common Git commands used for various tasks such as creating repositories, making changes, syncing repositories, and parallel development. Key commands include 'git init' for initializing a repository, 'git add' for staging files, 'git commit' for committing changes, and 'git push' for pushing changes to a remote repository. Additional commands like 'git clone', 'git pull', 'git branch', and 'git stash' are also explained to manage collaborative development effectively.

Uploaded by

Shivanand Poosa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Common Git Commands

Copyright IntelliPaat, All rights reserved


Common Git Commands
You can do the following tasks, when working with git. Let us explore the commands related
to each of these tasks

Creating Repository Making Changes

Parallel Development Syncing Repositories

Copyright IntelliPaat, All rights reserved


Common Git Commands – 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
Creating Repository

Making Changes

Syncing Repositories

Parallel Development

Copyright IntelliPaat, All rights reserved


Common Git Commands – 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
Creating Repository

Making Changes

Syncing Repositories

Parallel Development

Copyright IntelliPaat, All rights reserved


Common Git Commands – git add
Since no files are being tracked right now, let us now stage these files.
For that, enter the command git add. If we want to track all the files in
the project folder, we can type the command,
Creating Repository
git add .

Making Changes

Syncing Repositories

Parallel Development

Copyright IntelliPaat, All rights reserved


Common Git Commands – 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”
Creating Repository

Making Changes

Syncing Repositories

Parallel Development

Copyright IntelliPaat, All rights reserved


Common Git Commands – 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
Creating Repository
git remote add origin “<URL to repository>”

Making Changes

Syncing Repositories

Parallel Development

Copyright IntelliPaat, All rights reserved


Common Git Commands – 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
Creating Repository This command will then prompt for username and password, enter the values and
hit enter.

Making Changes

Syncing Repositories

Parallel Development

Copyright IntelliPaat, All rights reserved


Common Git Commands – git push
Your local repository is now synced with the remote repository on
github
Creating Repository

Making Changes

Syncing Repositories

Parallel Development

Copyright IntelliPaat, All rights reserved


Common Git Commands – git clone
Similarly, if we want to download the remote repository to our local system, we can
use the command git clone <URL>. This command will create a folder with the
repository name, and download all the contents of the repository inside this folder.
Creating Repository In our example, repository contents were downloaded into the ”devops” folder.

Making Changes

Syncing Repositories

Parallel Development

Copyright IntelliPaat, All rights reserved


Common Git Commands – 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
Creating Repository to pull the latest changes, that others might have pushed to the remote repository

git pull <URL of link>

Making Changes

Syncing Repositories

Parallel Development

Copyright IntelliPaat, All rights reserved


Common Git Commands – 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
Creating Repository
git branch <name-of-new-branch>

Similarly, to delete a branch use the command


Making Changes
git branch –D <branch name>

Syncing Repositories

Parallel Development

Copyright IntelliPaat, All rights reserved


Common Git Commands – git checkout
To switch to the new branch, we type the command

git checkout <branch-name>


Creating Repository

Making Changes

Syncing Repositories

Parallel Development

Copyright IntelliPaat, All rights reserved


Common Git Commands – git log
Want to check the log for every commit detail in your repository?
You can accomplish that using the command

git log

Copyright IntelliPaat, All rights reserved


Common Git Commands – git stash
Want to save your work without committing the code? Git has got you covered.
This can be helpful when you want to switch branches, but do not want to save
your work to your git repository. To stash your staged files without committing just
Creating Repository 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

Making Changes

Syncing Repositories

Parallel Development

Copyright IntelliPaat, All rights reserved


Common Git Commands – git revert
This command helps you in reverting a commit, to a previous version

git revert <commit-id>

<commit-id> can be obtained from the output of git log

Copyright IntelliPaat, All rights reserved


Common Git Commands – git diff
This command helps us in checking the differences between two versions of a file

git diff <commit-id of version x> <commit-id of version y>

<commit-id> can be obtained from the output of git log

Copyright IntelliPaat, All rights reserved


India : +91-7847955955

US : 1-800-216-8930 (TOLL FREE)

[email protected]

24X7 Chat with our Course Advisor

Copyright IntelliPaat, All rights reserved

You might also like