Thinking Box

How to Use GitHub / Download Git, Create a new repository, Upload file ๋ณธ๋ฌธ

์นดํ…Œ๊ณ ๋ฆฌ ์—†์Œ

How to Use GitHub / Download Git, Create a new repository, Upload file

๋ ˆ์•ผ_Reya 2024. 3. 18. 16:55

Using GitHub, you can easily manage your code and collaborate with other people without having to worry about losing your files. Let's find out the whole process.

1. Download Git.

๐Ÿ‘‰๐Ÿป Git Download Site

https://git-scm.com/download/win

 

Git - Downloading Package

Download for Windows Click here to download the latest (2.44.0) 32-bit version of Git for Windows. This is the most recent maintained build. It was released 23 days ago, on 2024-02-23. Other Git for Windows downloads Standalone Installer 32-bit Git for Win

git-scm.com

 

You may refer to the page below and follow the screenshots showing each step of the downloading process.

 

https://velog.io/@hyun_ha/Git-%EA%B0%9C%EB%85%90-%EB%B0%8F-%EC%84%A4%EC%B9%98%ED%95%98%EA%B8%B0

 

Git ๊ฐœ๋… ๋ฐ ์„ค์น˜ํ•˜๊ธฐ

์ฝ”๋“œ ๋ฒ„์ „ ๊ด€๋ฆฌ ํ”„๋กœ๊ทธ๋žจ์ด๋‹ค.git์œผ๋กœ ๊ด€๋ฆฌํ•˜๋Š” ํ”„๋กœ์ ํŠธ๋ฅผ ์˜ฌ๋ ค๋‘˜ ์ˆ˜ ์žˆ๋Š” ์‚ฌ์ดํŠธ๋ฐฑ์—… + ํ˜‘์—…์ด ๊ฐ€๋Šฅํ•˜๋‹ค.Git - ๋ฒ„์ „ ๊ด€๋ฆฌ๋ฅผ ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ์†Œํ”„ํŠธ์›จ์–ด ์ž์ฒดGitHub - git์œผ๋กœ ๊ด€๋ฆฌํ•˜๋Š” ํ”„๋กœ์ ํŠธ์˜

velog.io

 

 

 

2. Create a new remote repository in your GitHub.

โ“GitHub Repository
A remote place where you can store your code, files, and each file's revision history.
You can easily track changes made to files in a project and navigate revisions.
Using a public repostiory makes your life so much easier when working with with other developers. Everyone can easily pull and push changes from the remote repository instead of having to share files all the time.
Plus, there is no risk of losing important files which can happen when you use a local repository.

 

> Click "Your Repositories".

 

> Click "New".

 

> Create!

 

 

3. Create a local repository in your computer.

> Right-click the folder that you want to upload to GitHub.

> Select "Git bash here".

 

> Use git init command to initialiize a new repo.

 

 

4. Connect two repositories you just created.

> Enter the repository you created in GitHub.

> Find out the repository address.

 

> Use the remote repository address to connect with the local repository.

> Enter git remote add origin and type the address. 

 

โ€ปCAUTION: If you just copy and paste the address, the form changes like below.

 

> If you made a mistake or simply want to delete the repository which is currently connected,

   use the git remote rm origin command. (rm = remove)

 

> Finally, check if the remote repository is successfully connected to the local repository.

> If the connection was succeessful, the command will return the remote repository address.

"MyGit" folder is successfully connected with "Repository1" in GitHub.

 

 

5. Take preliminary steps before file uploading.
(Manage your repository's settings)

> Change the branche name. ("master" → "main)

Branch name is successfully updated.

 

> Set the branch default name as "main".

> Going forward, every local repository branch name becomes "main".

 

> Pull README.md. (Except the case if you didn't add README file when you created the repo.)

โ€ป Pull : Bringing a file in remote repository to local repository.

> Always git pull before uploading any files to GitHub to make sure the local repo is up to date.
   Without git pull, your local branch wouldn't have any of the updates that are present on the remote. 

 

*git pull --all : You can fetch all remotes by using this command. This is handy if you are working on a fork or in another use case with multiple remotes.

 

 

6. Upload file.

There are three stages here: Add → Commit → Push.

 

 

1) Add

> To upload a specific file to GitHub: git add [filename]

 

 

> To upload all updated files in the folder: git add .

*git add . : Adding all of the "updated" files. For example, if you only updated one of the three files in your folder and use this command, only the revised one file will be reflected on the GitHub.

 

 

*git status : To check what are the updated files in the current local repo. You can use this command before adding.

It shows the list of all the updated, added, or deleted files in red.

Red means untracked files, or that they are not added to staging area yet.

After adding, the color changes to green becuase now they are tracked.

"GitSample" file is green after adding

 

* git rm --cached -r : Cancel all the added files.

* git rm --cached [filename] : Cancel specific added file.

 

 

2) Commit

Unlike <stage 1: Add>, it is relatively difficult to cancel commit, so be more careful in this stage.

Write commit message. Commit message is used to explain what kind of updates this commit includes.

   For example, if this commit is after you have fixed a bug, you can write git commit -m "fix: which bug".

   Commit message should be consistent and easy to understand.

   *Search "git commit convention" to find out more about consistent commit messages.

commit message (gray writing on the right)

 

> git commit -m "commit message".

   An error occurred here.

Error: Account's default identity needs to be set.

 

> To resolve, follow the message and enter your email address and user name.

 

> Now, try commit one more time.

Successfully committed

 

 

3) Push

> Push the file in local folder to the remote repo: git push origin [branch name]

git push origin [branch name]

 

Successfully uploaded to GitHub now

 

You can see the updated file in the GitHub Repository

 

*When you already have a repository...

If there is a repository and there are files uploaded, you just have to upload the updated files to GitHub.

Simply enter the commands as below. (When the branch name is "main")

 

The first line is not mandatory, but only applies when necessary.

For example, if your team member added something to main branch, there would be discrepancies with your file.

In this case, you first have to git pull to update your file as your team member's.

Even if you forgot and activated git push, there would be a message saying you need to git pull first.