Git Cheat sheet

** Still a work in progress :-) **

Customization

Git repository:
Git username:

I did add the option to inputbind your Git password, but if you do not feel comfortable inputting passwords into this site I recommend copying the command into a text editor and adding it there. You can also use Github’s GUI to retrieve the SSH URL, how to do this is shown later.

Git password:

Starter commands

Adding an existing remote to an existing project directory

Initialize a git repository in the directory

git init

Add the git repository as origin

git remote add origin #@GITREPO@#

Set branch to master

git config branch.master.remote origin

git config branch.master.merge refs/heads/master

Pull any files from repository (like README or LICENSE files)

git pull

Create a push-helper

Instead of using the inputbinder on this site to generate the Git URL you can also use the GUI to find the SSH url. Go to your repositories’ page and click on SSH.

alt text

Copy the link to your clipboard

alt text

sudo nano push.sh

  #!/bin/bash
  echo "Pushing changes..."
  git push https://#@GITUSERNAME@#:#@GITPASSWORD@#@github.com/#@GITUSERNAME@#/#@GITREPO@#.git
  echo "Script finished"

Add the push.sh file to your .gitignore

echo '/push.sh' >> .gitignore

Make the push.sh file executable

sudo chmod +x push.sh

Add changed files to staging

git add .

Commit staged files

git commit -m "Initial commit"

Use push.sh to push changes

. push.sh

If you would like to use aliases for running the push command, check out my blog post about bash here.

However great using the Git command line is, there are plenty of other ways to work with the Git protocol. The, in my opinion, two greatest candidates are GitKraken (cross-platform) and SourceTree (Windows).