Use Git bash ssh tools on Windows from cmd

I needed ssh functionality for Windows cmd when using Git, but I do not want to use git bash. It turns out the git bash ssh tools also work from cmd. All you have to do is add the bin directory they are in to your path.

set path=%path%;"C:\Program Files\Git\usr\bin"

That’s it.

Advertisements

Adding a ssh public to Gitlab

I needed to add my ssh public key to Gitlab. Pretty straight forward generating it using PuttyGen and saving the public and private keys. When I pasted they public key into the dialog in Gitlab and hit “Add key” I got the following error.

The form contains the following errors:

  • Key is invalid
  • Key should be a single line
  • Fingerprint has already been taken
  • Fingerprint cannot be generated

I checked the public key and saw that it was not a single line. To correct this I did the following.

  • Deleted the “—- BEGIN SSH2 PUBLIC KEY —-” line
  • Deleted the “—- END SSH2 PUBLIC KEY —-” line
  • Deleted the “Comment: …” line
  • Removed all line ends from the generated key
  • Added “ssh-rsa ” before the key
  • Make sure there is an empty line after the key

That’s it.

Git quickstart

Just some short notes to remember how to get started with Git.

Check version

$ git --version

Setting-up

Set the following configuration items if using Git for the first time, as these values are used for each commit made.

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"

Initializing a new Git repository

Make sure you are in the top-level folder of your project and then run the following command.

$ git init

Create the .gitignore file

Git has a special file called ‘.gitignore’ that allows you to specify which files to NOT include in your repository.  The following file is based on the recommended .gitignore file for Python from GitHub.

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
 
# PyCharm files
.idea/
 
# Instance Folder - used for sensitive configuration parameters
/instance

Setting remote repository
Make sure you are in the top-level folder of your project and set up the remote repository.

$ git remote add origin [email protected]:nidkil/name-of-repository.git

Check the remote repository has been set correctly.

$ git remote -v

Staging files
The standard flow for adding files to your git repository is to create/edit the files, add them to the staging area, and then commit them to your repository.

$ git status
$ git add .
$ git status

Initial commit
The following command makes the first commit to the repository, including a message describing the commit.

git commit -m "Initial version"

You can confirm that the commit was successful by checking the log of the repository.

git log

Push to the remote repository
To push the local Git repository to the remote Git repository.

$ git push -u origin master

Working with a feature branch
A common method of developing features is to create a feature branch where you implement specific functionality and then merge the changes back into the master or development branch. Follow the process: create a new feature branch, make changes and merge changes back into the ‘master’ branch.

Create a new feature branch.

$ git checkout -b name_of_feature_branch

Check new feature branch was created (the star next to ‘name_of_feature_branch’ branch indicates it is the current branch that we are working in).

$ git branch

The following commands stage, commit and merge the changes into the local repository.

$ git add .
$ git status
$ git commit -m “Added use of templates and Bootstrap”
$ git checkout master
$ git merge add_templates

Delete the branch.

$ git branch -d add_templates

Push the changes into the remote repository.

$ git push -u origin master

Deleting a remote tag in Git

Today I deleted a tag in Eclipse using EGit that was already pushed to the origin. I then discovered that once the tag is deleted in the local repository there is no way in EGit to delete it from the origin. I am using Github as remote repository. So I checked if the tag could be deleted there. Unfortunately I could not find a delete option there. Bummer what now? Command line git to the rescue. Continue reading

Yes you can: Diff with EGit in Eclipse!

In my previous post on how to quickly view all the changes between two branches in Git I ended with the statement “Is there away to do the same in Eclipse with EGit?“. I Googled around for the answer a bit, but with no success. By accident I just discovered how to compare the working version of a file to the commited version. Not entirely the same, but getting closer 🙂 For the purpose of being able to quickly check what changes I have made to write meaningful commit messages this is sufficient for me.

Anyway, these are the steps:

  • Open Git Staging (Window > Show view > Git > Git Staging)
  • Double click on a file in “Unstaged Changes” or “Staged Changes”

And voilà! There is a beautiful window with a side to side diff of the working version and commited version. Nice! I hope this is useful.