Thursday, October 19, 2017

My simple cheat-sheet of Git bash commands

This post has several assumptions!

1) You are working on a Windows machine with https://git-for-windows.github.io/ already installed.
2) You already have a Github user and have created a repository with content
3) Assumes you already have created a github ssh key and its already working - I will make a blog post about doing this easily soon!
4) This also only works when you are only working on the ONE default branch!!

Essential Github bash commands:

To clone something you have in the Github site to your PC

On the webpage:
- Go to your profile and click on the repo
- Find the "clone or download" button
- Click Get SSH if you need, and copy something like git@github.com:arielsanchezmora/arielsanchezmora.github.io.git to your clipboard.

Open Git Bash:
- Find the directory where you want to copy the repository to
- In the Git Bash Window type "cd /c/....(the path, but in linux format. use "pwd" if you get lost on how to format it)
- Git clone [what you had copied from the webpage: git@github.com....]
(type ssh key password if needed)

To return changes to Github

Change to the cloned folder (it will have a hidden .git folder) before executing the below. The other files should have changed before you run these commands.

git status to see the changes (red is unstaged changes)
git add . (the dot means all files/subfolders)
git status (green shows changes have been staged)
git commit -m "add a comment to your code change" (otherwise, hi vi!)
git status will show your local branch is ahead of the Github site
git push origin master will sync your changes back to Github :)