Git

What are Git Stash and Git Pull Commands

Sometimes developers modify the source code files and commit these changes to the Git repository. However, they don’t want to push them to the remote server. In such a scenario, they can temporarily hold them through stash operation.

When they complete their work on the Git repository, they need to push all changes to the GitHub server. For this purpose, they are required to up-to-date the local repo with remote first. To do so, the “git pull” command can be used.

This study will discuss:

What are git stash and git pull Commands?

The “git stash” command is utilized to temporarily hold the changes. It can be used when the user doesn’t want to add the newly added changes to the Git repository and modify them later. On the other hand, the “git pull” command can be used to download the updated version of the remote repository.

How to Perform ‘git stash’ in Git?

Follow the steps below to keep the most recently added changes with the help of the “git stash” command.

Step 1: Redirect to Git Repository

Navigate to the Git desired repository by typing out the “cd” command:

$ cd "C:\Users\nazma\Git\coco2"

Step 2: Make and Update File

Then, execute the “echo” command to generate and update the file immediately:

$ echo "my new python file" >> file1.php

Step 3: Track Changes

Next, push the newly added changes into the staging area through the “git add” command:

$ git add file1.php

Step 4: Commit Changes

After that, run the “git commit” command to commit all changes to the Git repository:

$ git commit -m "new php file added"

Step 5: Stash Changes

To temporarily hold all added changes, use the “git stash” command:

$ git stash

How to Use ‘git pull’ Command in Git?

To download the updated version of the GitHub repository, perform the below-stated steps.

Step 1: Move to Git Repository

First, switch to the particular repository by running the “cd” command:

$ cd "C:\Users\nazma\Git\perk5"

Step 2: Create and Update File

Then, run the “echo” command to generate and update the file simultaneously:

$ echo "new python file" >> file5.py

Step 3: Push Changes to Tracking Index

Now, add all modifications into the staging area by running the “git add” command:

$ git add file5.py

Step 4: Commit Changes

Next, execute the “git commit” command to update the Git local repository:

$ git commit -m "new python file added"

Step 5: View Remote URLs List

To check the existing remote URL list, utilize the “git remote” command:

$ git remote -v

Step 6: Git Pull

Lastly, run the “git pull” command to download the updated content of the remote repository:

$ git pull

That’s all! We have provided the difference between the ‘git pull’ and ‘git stash’ commands.

Conclusion

The “git stash” command can temporarily hold the changes. It can be used when the user doesn’t want to add the newly added changes to the Git repository and modify them later. On the other hand, the “git pull” command can be used to download the updated version of the remote repository. This study elaborated on the “git stash” and “git pull” commands.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.