In this multi-part series, we will go over various aspects of working with Git and GitHub. We will use the projects created in this website as a practical workspace. In this post, we will add the Eclipse project created here to Git and GitHub. Make sure that Git is already installed as described here and an account created in github.com.
Create empty repository in GitHub
Login to account in github.com and click to create New repository
Click ‘Create Repository’. In next screen, click on ssh option:
Tell Git who you are
Open Git Bash terminal (from windows Start->All Programs) and set some basic configuration.
1 2 3 4 |
cd /c/tvi/Software/workspace_mars/standalone-utils git config --global user.name "Sunil Mogadati" git config --global user.email "sunil@techvalueinsight.com" git config --global core.editor="C:/Windows/system32/notepad.exe" |
Create Local Git repository
Initiate a new git repository in project directory.
1 2 |
cd /c/tvi/Software/workspace_mars/standalone-utils git init |
It gives a message “Initialized empty Git repository in C:/tvi/Software/workspace_mars/standalone-utils/.git/”
Register new repository with Remote Git repository
GitHub is the remote we want to push the code to. URL for the repo can be found on github repository.
1 |
git remote add origin https://github.com/sunilmogadati/standalone-utils.git |
Create .gitignore file
We need to tell git to ignore the files that we do not want to commit to git (java class files, package files, IDE files etc.). The .gitignore file resides in project root directory (C:\tvi\Software\workspace_mars\standalone-utils)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# Refer https://raw.githubusercontent.com/github/gitignore/master/Java.gitignore *.class # Mobile Tools for Java (J2ME) .mtj.tmp/ # Package Files # *.jar *.war *.ear # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* # Eclipse files .classpath .project .settings # Maven target # Backup files *.bak # Mac .DS_Store # IntelliJ *.iml .idea |
Add project files to staging
1 |
git add . |
Initial commit
1 |
git commit -m "First version" |
Verify commit
Push to GitHub
It prompts for github account’s username and password.
1 |
git push -u origin --all |
Verify in GitHub