Getting Started with GitHub
1. Environment Setup
1-1. JAVA: 1.7
1-2. Eclipse: Kepler - Install Eclipse EGit Plugin
The EGit plugin integrates Git with Eclipse. There are two ways to install the EGit plugin in Eclipse: the first method is using Eclipse Marketplace, and the other method is using Install New Software.
[Method 1] Marketplace
- Select Help > Marketplace.
- In the Find field, search for "git" and select EGit – Git Team Provider to install.
[Method 2] Install New Software
- Select Help > Install New Software.
- Add
http://download.eclipses.org/egit/updates
to Work with, select the plugin, and click the next button to proceed to the next step.
- Detailed installation options will appear, continue clicking Next to proceed. Since the supported Eclipse version varies for each EGit version, refer to the guide at the following link for EGit installation:
EGit FAQ
- After reviewing the License information, select "I accept the terms of the license agreement" and click Finish to begin the installation.
- The EGit plugin will begin installing.
- You will be able to confirm that the EGit plugin installation is complete.
- After EGit is installed, go to Window > Show View > Others… and confirm that the Git option has appeared. Add the Git > Git Repositories tab.
- You will see the Git tab added, as shown below.
2. Using GitHub
2-1. Signing Up for GitHub
To use GitHub, you need to sign up on the website below.
- GitHub: https://www.github.com/
2-2. Adding a Repository
- Log in to GitHub and click the “+” icon next to your user ID at the top-right corner, and the "New repository" menu will appear.
- Selecting “New repository” will take you to a page where you enter the information needed to create the repository.
- Enter a name for the repository in the "Repository name" field and a description (optional) in the "Description" field. If you plan to clone the repository, check "Initialize this repository with a README," and choose .gitignore and license based on the nature of your project. When everything is ready, click the Create repository button to create the repository.
- After clicking Create repository, the repository will be created.
2-3. Linking GitHub with Eclipse
Clone: Checkout
When you want to join an existing project or copy a Git repository, instead of using checkout like Subversion, you use the clone command. This means that Git copies all the data from the server, unlike Subversion. When you execute clone, you will get the entire project history, so even if the server disk fails, you can recover all the data by restoring any local repository.
- To add the repository, you need to input GitHub information. Copy the Clone URL from GitHub (either HTTPS or SSH).
- Click the Git tab to go to Git Repositories. Select “Clone a Git Repository,” and a screen will appear to add the repository. The URL you copied will be automatically entered.
- Select the branch to clone. If only master or main branches exist, choose either master or main and click next to proceed to the next step for cloning.
- Specify a location to save the repository locally and click Finish. If you select "Import all existing projects after clone finishes," the repository will be saved locally and automatically imported.
commit & push : commit
Git manages the local repository and the remote repository separately when modifying, saving, and sharing files. The process can be divided into two actions: committing to the local repository and pushing to the remote repository. A commit creates a snapshot and updates the HEAD.
- Right-click on the project in the "Project Explorer" > Select Team > Commit.
- Write a message/change log for the commit > Select the files to commit.
- After committing, the changes are applied only to the local repository and not to GitHub (remote repository).
- Clicking the "Commit and Push" button will apply the changes directly to the remote repository. If multiple people have cloned the repository, and someone else has already pushed, you cannot push until you first fetch their changes and merge them before pushing.
Fetch & Merge: Update
If someone pushes to the remote repository, you need to reflect the changes from the remote repository to your local repository. To merge the remote repository’s changes into your local repository, you need to pull. When you pull, it fetches the changes from the remote repository and then automatically performs the merge. The action of fetching data from the remote repository to the local repository is called Fetch. In other words, pulling is a combination of fetching and merging. (It is generally recommended to use fetch first, and then merge, rather than pulling directly.)
- Right-click on the project in the "Project Explorer" > Select Team > Choose "Synchronize Workspace."
- Pull or merge. The Eclipse EGit plugin offers an option to automatically fetch before synchronizing. Go to Window > Preferences > Team > Git > Synchronize to see that the option is checked. This means that before synchronization, fetch will always be performed to update the local repository with the remote repository’s changes.
2-4. Adding a GitHub Project
- First, create a new project on GitHub that you want to add.
- After creating the project, right-click on the project and select Team > Share Project to add the GitHub repository to the local project.
- Selecting Team > Share Project will open a popup window like the one below.
- Choose the Local Repository and click Finish to add the project to the repository.
- After adding the project to the Local Repository, the Git repository name and branch name will appear on the right side (e.g., namoo.board - Repository Name, master - Branch Name). Newly created files will show a "?" icon, and modified files will show a ">" icon.
- To save the newly created project to the Local Repository, right-click on the project and select Team > Commit.
- After selecting Commit, the Git Staging window will open. Write a description for the commit in the Commit Message, review the list of files to commit, and select the files you want to commit. Click Commit to save it to the Local Repository. Clicking "Commit and Push" will save it to both the Local and Remote Repositories simultaneously.
- After committing to the Local Repository, you need to push the changes to the Remote Repository. To do this, right-click on the project and select Team > Remote > Push...
- If a Remote Repository has already been set, select the appropriate Remote Repository from the drop-down list and click Next to proceed.
- Alternatively, select "Custom URI" and input the URI for the Remote Repository, then enter your GitHub username and password, and click Next to proceed.
- The next screen will allow you to select the reference settings for the repository. Initially, it will show nothing, but when you click the "Add All Branches Spec" button, it will display all the branches you wish to push. Click Finish to complete the push. The Push Result Report will appear, showing the list of items pushed to the Remote Repository. The remote server where the push was completed will be displayed in the bottom box. Click OK to close the dialog. If you want to push all tags, click the "Add All Tags Spec" button. 12. Log in to GitHub and check the project you pushed on the web interface. 13. In Eclipse, go to Git Repositories > Branches > RemoteTracking to merge and import the changes into your local repository.
- Log in to GitHub and check the project you pushed on the web interface.
- In Eclipse, go to Git Repositories > Branches > RemoteTracking to merge and import the changes into your local repository.