How to Paste in Git Bash?

Git bash is a command line window to manage source code of an application. For application developers, Git Bash is an inevitable tool. While writing the code, they use commands for various actions such as pulling the latest committed code, merging the code and pushing the code to code repositories. When it comes to source code repository, be it Github, Gitlab or any other source code management tool, Git Bash and commands are mandatory to control versions of source code at each code commit.

In complex development environments, Git is very useful in speeding up the process of development.

In this article, we will see:

Most used Git Commands using Git Bash

NOTE: Before applying commands using Git Bash, you should be connected to Git using your username and password of Git account.

Command 1: git init {Repo Name}

Enables you to create a new repository. In the above command, Repo Name is the repository name you want to keep.

Command 2: git clone {URL}

Allows you to download repo on your local environment. URL is the path from which the repository is available.

Command 3: git commit -m {“the comment of changes you have made”}

Allows you to put your code files to the centralized source code repository and to enter notes of changes you have made in this set of files.

Command 4: git log 

Shows you the version history of commits in the current branch.

Command 5: git checkout {Branch Name}

If you want to switch from one branch to another branch, use this command. {Branch Name} is the branch you want to switch to.

Command 6: git pull {Repo Link}

Enables you to pull requests to your local repo to update your repo with latest changes made by others.

Command 7: git push {variable} {branch}

This command is the other way to “pull command”. It pushes all your changes to the specified branch on the centralized source code repository.

Command 8: git stash {variable} {branch}

This command is to store your changes temporarily and you can move to another task, come back and apply your final commit. The command is very helpful to save uncommitted changes while switching the context.

Scenarios in which “Paste Command” is useful

All the above commands are used more than 100s of times a day when a developer is continuously coding. Pasting the same commands used previously makes it easier and faster to execute them and switch to the next task. Folder paths or urls in the command are usually long and to be types each and every time you want to push your changes or perform any action. Pasting the authentication keys or any hash values are handy when it cannot be remembered to type. Another scenario is you want to use the same commands in sequence while coding, you just do “Paste” the command and do not keep typing the same command again and again.

Git Bash command line window provides the Paste option to deal with the above scenarios.

Somehow, by doing CTRL+V – Paste doesn’t work in Git Bash

In Windows 10, Shell Command Line does not allow CTRL+V if settings are not enabled. At times, new developers struggle to figure out why the shortcut does not work with the command most common and familiar to all of us.

Enable the “Paste” action for Git Bash in Windows 10 (Shell Command Line)

  1. Open the Git Bash command window.
  2. On the window top bar, right-click to open a menu.
  3. Choose the last option, Properties.
  4. Edit Option section: tick the following check boxes.
    • Quick Edit Mode
    • Enable Ctrl key shortcuts
    • Use Ctrl+Shift+C/V as Copy/Paste
Paste Option
  1. OK to save changes.

How to Paste in Git Bash (Windows 10)

NOTE: After enabling the key shortcuts as above, follow the steps to paste in Command Line.

  1. Open the command line.
  2. Enter the command for the first time and copy it.
    • CTRL+C
  3. The next time you want to use the same command, use CTRL+V. 
    • You can also use the Insert key to paste.
    • You can also use the right-click→Edit→ Paste from the menu. 
  4. It works!

How to Paste in Git Bash in Linux

  1. Open the command line.
  2. Copy the command with CTRL+Insert.
  3. Paste the command text with SHIFT+Insert.
  4. It works!

The more you use, the faster it becomes

As it is said “Practice makes man perfect”, applies in this use case as well. The more you practice working on git commands using terminal, you become faster and learn shortcuts to do it faster. It’s all about learning and improving on how you produce faster and quicker outputs. Executing Git Bash commands help you do your coding tasks faster, maintain the version history of your Git commits, revert back your changes if needed, cherry pick you changes if you need to pull your code and merge with another branch in case of a sudden fix required. 

All this is possible with Git with just one-liner commands. Also, pasting the same set of commands, again and again, is even better in terms of faster delivery!

You may also like:

How to Delete a Repository in GitHub