Pushing Initial Project Code to a Newly Created Github Repository

  1. Create a new Github repository on your account, say TestRepo
  2. Create SSH public and private keys for your machine, and add that SSH key to your Github account
  3. Go to your project directory and create a .gitignore file for files and folders you do not want to publicly upload to your Github repository
  4. Open the command prompt, by pressing the Window and R keyboard buttons at the same time, typing in cmd, and pressing Enter
  5. In the command prompt, go to the root of your project code, say cd C:\Users\Your_Machine_Name\Test_Project
  6. Run git init
  7. Run git add . 
  8. Run git commit -m ‘Initial commit’. You can replace the commit message with a desired message if you want to.
  9. Go to your newly created Github repo and copy its SSH address, i.e. git@github.com:github_username/TestRepo
  10. Back to the command prompt, run git remote add origin git@github.com:github_username/TestRepo
  11. Run git push -u origin master

Update: Pushing latest changes to the repository

  1. Back on the command prompt, run git status to display the files where changes were last made
  2. Copy the path of the file you want to commit, then run git add <filename> for each file. Run git add -u if you want to include everything except the new files. Run git add -A if literally all files needed to be committed.
  3. Run git commit -m <commit message> to ready the files for transfer to your repository
  4. Run git push -u origin master to push these changes

Update: Creating and/or Moving to a particular branch of code

  1. On the command prompt, run git branch to display all the branches available to you locally. By default, there is only one branch, aptly named as master.
  2. If you want to build a new branch from master, run git checkout -b <branch_name>. This creates and automatically moves you to the new branch.
  3. If you want to move to another branch, run git checkout <branch_name>.

Update: Merging Branches

  1. Run git merge <branch_name> if you want to merge that branch to the branch where you are currently in.

Update: Deleting branches

  1. Run git branch -d <branch_name> if you want to delete a branch. This will delete that branch in your local repository.
  2. Run git push origin –delete <branch_name>. This will delete the selected branch in the remote repository.

Update: Retrieving latest version of code

  1. Run git fetch origin.
  2. Run git reset –hard origin/master. Note that this will effectively remove all files locally and replace them with the latest files found in the remote repository.