Site icon TestingDocs.com

Practical Git Commands

Introduction

In this post, we will discuss some practical Git Commands. These are frequently used commands while working with automation using Git. Git is a distributed version source control system.

init

To initialize a Git repository, type the following command:

/> git init

status

/> git status

To know the project status. It’s healthy to run git status often. Sometimes things change and you don’t notice it.

Adding Changes

When we add a new file, we will notice that Git says it is “untracked”. Git sees that as a new file. To tell Git to start tracking changes made to sample.txt, we need to first add it to the staging area by using git add.

/> git add sample.txt

staged:
Files are ready to be committed.

unstaged:
Files with changes that have not been prepared to be committed.

untracked:
Files aren’t tracked by Git yet. This usually indicates a newly created file.

To tell Git to start tracking changes made to a file , we first need to add it to the staging area by using git add.

git add sampleFile.txt

git reset

You can use git reset <filename> to remove a file or files from the staging area.

git log

Use git log –summary to see more information for each commit. You can see where new files were added for the first time or where files were deleted. It’s a good overview of commits.

git push

The push command tells Git where to put our commits when we’re ready. The -u tells Git to remember the parameters( like remote and local branch names ) , so that next time we can simply run git push and Git will know what to do.

git stash

Sometimes when you go to pull you may have changes you don’t want to commit just yet. One option you have, other than committing, is to stash the changes. Use the command ‘git stash’ to stash your changes, and ‘git stash apply’ to re-apply your changes after your pull.

 

Git Tutorial on this website can be found at:

https://www.testingdocs.com/git-tutorials/

For more details on the Git, visit the official website at:

https://git-scm.com

Exit mobile version