0% found this document useful (0 votes)
19 views

Git and GitHub Class Prepatory Steps

The document provides steps for students to prepare for a Git and GitHub class by setting up their accounts and environments. It details creating GitHub accounts and repositories, installing and configuring Git Bash, cloning repositories, and using basic Git commands.

Uploaded by

Kier Magday
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Git and GitHub Class Prepatory Steps

The document provides steps for students to prepare for a Git and GitHub class by setting up their accounts and environments. It details creating GitHub accounts and repositories, installing and configuring Git Bash, cloning repositories, and using basic Git commands.

Uploaded by

Kier Magday
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Git and GitHub Class Prepatory Steps

Hello Class,

Before we start with our Git class, we are trying to make sure that we will not encounter any
technical issues along the way. Our team, already requested access for all of us.

Please follow the steps below to get started with Git and GitHub. After doing all of the steps
below, I need you to reply to the group chat stating 'DONE' - 100% for example.

If you encounter any problems, please DM me (Mylene Arao-arao), so that we can fix try to fix
them together. Thank you.

1. Creating a GitHub Account


- go to github.com
- Choose a username
- Verify your email

2. Creating a GitHub Repository


- Click the '+' sign symbol on the upper right hand side.
- Click 'New Repository'
- Type the Repository Name. (The name of your repository should be significant to the files you
will store in it.)

- Select Public (this is a repository where everyone can access and download but they can't
modify it)
Note: Everyone can create a Private repository. You can change the visibility later
- Put a checkmark beside "Add a Read me file"
- Click "Create Repository"

3. Install Git Bash


The installer can be found in this path: \\192.168.129.253\Installers\GIT

You can also download it from this path:


https://git-scm.com/

Check if Git is already installed.

You can check whether Git is installed and what version you are using by opening up a terminal
window in Linux or Mac, or a command prompt window in Windows, or gitbash, and typing the
following command: git --version.

4. Check if git is already configured in your computer, by executing this command:


$git config --list

If it is not under your credentials, you can proceed with Step number 5, otherwise, proceed to
Step 6.

5. How to reset your Git Settings

$git config --global --unset user.name


$git config --global --unset user.email

6. Configure git bash

$git config --global user.name "YourUserNameInGitHub"

$git config --global user.email "YourGithubEmail"

7. Clone the repository that you created on GitHub


- Click your profile picture on the top right hand of your GitHub account.
- Click Your Repositories
- Click the repository that you want to clone.
- You will see a green button that is labeled <>Code.
Click the drop-down arrow beside the 'Code' button.
- Copy the URL link under HTTPS

CLONING REPOSITORY USING GIT BASH


- Open gitbash and execute the command below:
$git clone UrlAddressOfYourRepositoryInGithub

- Receiving objects should show 100%

- To get the present working directory, type


$pwd
- To check if the folder you cloned is there, type
$ls
- Open the folder of your cloned repository
cd repositoryName
- To get the current directory
$pwd
Note: Copy the file path or address

8. Working Around with Git Commands using Git Bash


Assuming that your present working directory is the folder of the repository you just cloned.
- Before we can add a file to git, we need to create a file
- For that let us use an echo command
$echo "This is file1.text" > file1.txt

- We will echo this to file1.txt


- So this will create a file1.txt file with the content, "This is file1.text" inside

- list the files again


$ls
- You will see we have created file1.txt file.
- Let us see what is in this file
$cat file1.txt

- Let us now add the file to the staging or index area


$git add file1.txt
- We are telling git to keep track of file1.txt and keep an eye out if there are any changes in the
file.

- Commit is like a snapshot that we can restore later if necessary. We can revert at a certain
point in other words
$git commit -m "Message"
- Your message should be something meaningful. It should be short but powerful.

- To check the status of your current working directory:


$git status

Sample Output:

mylene.araoarao:
$ git status
On branch main
Your branch is ahead of 'origin/main' by 2 commits.
(use "git push" to publish your local commits)

nothing to commit, working tree clean

- This means that the active branch is main.


- You made two commits in your local repository that are not yet known in the remote repository
(Github in this example)
- Git has nothing to complain about (so all our files are under Git control)
- So we basically push or update our remote or external repository.
$git push -u origin main

- Enter your GitHub username and password if it will ask you.


- It will upload all our basically commits to the remote repository.
- When you check your GitHub account, it will show your latest push.

9. Integration of Git and Eclipse

To Create a Repository In Eclipse


- Open Eclipse
- Go to Perspective
- Search for Git Repositories
- This will now open the Git repositories perspective.

A. To Open a Local Existing Repository


- Click 'Add an existing local Git repository
- Under the directory, click 'Browse'
- Look for the folder where the cloned repository is saved.
- Uncheck 'Skip hidden directories'
- Under the Search results, click the git path
- click 'Add'

B. To Add a project to the git repository


- Create a project in Eclipse
- Do a right click on Project > Team > Share
- Click the drop-down arrow beside the repository and Select the repository.
- Click Finish

NICE TO KNOW:
OTHER WAYS OF CLONING A REPOSITORY FROM GITHUB
a. First Way To Clone a Git Repository

- Work under Git repositories perspective.


- Click 'Clone a Git repository.'
- Click 'Clone URI'
- Click Next
- Copy the URL link from GitHub > Repository > Code > Local > HTTPS
- Paste the HTTPS url in Location > URI
- Click Next
- In your Git Perspective, it should now show the Git repository that you just cloned
.

b. Other ways to clone a Git Repository


- Open Eclipse
- Right-click anywhere in the space under Package Explorer.
- Click Import
- Click the arrow to the right beside 'Git'
- Select 'Projects from Git'
- Click 'Next'
- Select 'Clone URI'
- Click Next
- Under Location > URI > paste the HTTPS link of the git repository
that you want to clone.
- Under Authentication > Put the username and password of your GitHub account.
- It will now show you the current branches of your GitHub repository.
- Click 'Next'
- Click 'Next'
- You can enter security questions to recover your password in case you forgot it.
- Click Finish

10. How to Commit Code to From Eclipse to Github


- Open the code in Eclipse.
- Make some changes to the code.
- In the Package Explorer, right-click the Project folder
- Click 'Team'
- Click 'commit'
- Drag the files that you want to commit from the 'Unstaged Changes' window to 'Staged
Changes'
- Type your Commit Message. The message you are going to put there should be significant on
the changes that you have made.
- Click 'Commit'
- Open your GitHub repository. It should now show the recent changes that you commit.

11. Working With Teams For your group project.

Collaborator Access
- GitHub gives collaborators access to a maximum of three members if the repository is Private,
whereas unlimited members for Public repositories.

- Open your GitHub repository.


- Click Settings
- Under 'Access', click 'Collaborators'
- Click 'Add people
- Type the username, email, or full name of the person you want to be a collaborator of your
repository.
- Click 'Add username to this repository.'
- It will now show 'Pending Invite'
- The collaborator should accept the invite.

- It will show in the notification of the collaborator that he or she is invited to be a collaborator of
your repository.
- The collaborator can now see your code.
- You can also delete the collaborator by clicking the delete icon under Settings > Manage
Access

Note: You can either use GitBash or Eclipse Git Perspective in pushing the code to your
Team's repository.

******
USING GIT BASH
1. Group Members will clone the repository of their leader. After cloning. Create your own
branch
$ git branch YourBranchName
$ git checkout YourBranchName

2. Your first commit after making your code

To add a single file to Git, we can use the add command like so:
$git add README.md

You can also add all open files by using a .


$git add .

$git status
If we rerun the status command, we should see that the readme file is now tracked. (color
green)

$git commit -m "Describe your commit"

-m: Pass a message as the commit message

If we would now rerun the status, we would see nothing is outstanding


.

3. Add GitHub as a remote

- Execute the following command you just got from GitHub. (Make sure this is your repo URL)

$git remote add origin [email protected]:rebelchris/git-test.git

We add a remote with the name origin in the above step. You can name this differently, but the
origin is the default and most common.

4. Push git changes to GitHub

We need to run the following command to push to GitHub as we just set up.

$git push origin master

Here we tell git to push to our origin remote on the master branch.

And if you now head over to GitHub, you should see your code and commit.

*******************************

FAQ
1. Unable to push GitHub in Eclipse. Error " Push to GitHub has encountered a problem"
Reason:
Github: fatal: Authentication failed Support for password was removed on August 13, 2021
Solution:
- Fix: Authorized Error
- Login to your GitHub Account.
- Go to Settings from your user icon,
- From the sidebar select Developer Settings
- Personal Access Tokens -> Personal access tokens (Classic)
- Generate a new Token, select repo option (others if applicable)
- Copy the Token and Save It
- Go to Eclipse Preferences -> General -> Security -> Secure Store -> Clear Password
Cache
- Now try to do a Git Pull, you will get a prompt to enter your username and password. Enter the
git username and the token just generated and - click log in.
2. How to Add GitHub SSH Key
- Open Git Bash
- Paste the text below, substituting in your GitHub email address.
ssh-keygen -t ed25519 -C "[email protected]"

- Type the file name where you want to save the key.
- Enter the paraphrase twice.
- Press Enter
- Take note of the path of the file where the key was saved.
- Go to the said path and open the key file that ends in '.pub'
- Copy the SSH key

- Open GitHub
- Click your profile icon at the top right.
- Click Settings
- Click SHS and GPG keys
- Click New SSH key
- Type your desired title.
- Paste the key inside the textbox labeled 'Key'
- Click 'Add SSH key'
- It should now show the new SSH or authentication key.

You might also like