RetroFed Forum
Your home away from modern life.
Learning the Git
Post Reply
AuthorMessage
MastKalandar feddit.online MastKalandar@feddit.online
Joined: 2026-04-28
Quote

@forestbeasts@pawb.social can you please suggest some tutorial where a noob can learn about working with git ??

3   Original
FiniteBanjo feddit.online FiniteBanjo@feddit.online
Joined: 2025-12-23
#2 · (edited) Quote Reply

I'll do you one better, here is a list of tasks I want you to accomplish one at a time in order to familiarize yourself with git:

understand that there are two parts to a git repo: the "remote" which is stored online such as CodeBerg or GitHub, and a "local" which exists on your computer.

install a git bash console and enable the right click context for it

Throughout the process please refer to this document: LINK

right click within a new tutorial folder and open git bash OR open git bash manually and use cd to go to the folder

create a git repo in this folder with git init add a readme with git touch README.md then git add . then git commit -am 'hello world' and finally... we're NOT going to push, yet. DON'T PUSH YET.

Notice that git init created a new folder in your local repo, unless it's a hidden folder for whatever reason, called ".git"

Also notice that the git add command has a little period in it, that tells the git add to add information about all of your files in the repo to the .git folder. You can also add files individually, or you can use git rm to remove them individually until a commit is made.

Okay, we don't have any files to add! We have to make some! I want you to add a text file with a single line in it. Okay, now git add . and git commit -am 'added file'

Now, project folders aren't just going to be lines of texts, obviously, so let's add a media file! It can be an image or a video (a copy or something that won't be missed). with the commands we used earlier, and customize the commit message yourself this time.

UH OH! WAIT A MINUTE! Did your .git folder just increase in size dramatically? Oh dear, remote repos like CodeBerg only give you 750MB of space... We can't push this online! We need to keep the media files in our project file, but we need to make the git ignore the files! OH! I KNOW! LETS MAKE A .gitignore FILE! Make another new text file, delete the file extension, and name it .gitignore. In this folder we need to specify all the different files and folders that we won't be tracking, either because they get generated per session of our editor, because they're binary files: like images, models, or vidoes, or because we won't be making changes to them that need to be shared with the other collaborators.

Example of a .gitignore file for an UnrealEngine project, as a random example:

# Visual Studio 2015 user specific files  
.vs/  

# Compiled Object files  
*.slo  
*.lo  
*.o  
*.obj  

# Precompiled Headers  
*.gch  
*.pch  

# Compiled Dynamic libraries  
*.so  
*.dylib  
*.dll  

# Fortran module files  
*.mod  

# Compiled Static libraries  
*.lai  
*.la  
*.a  
*.lib  

# Executables  
*.exe  
*.out  
*.app  
*.ipa  

# These project files can be generated by the engine  
*.xcodeproj  
*.xcworkspace  
*.sln  
*.suo  
*.opensdf  
*.sdf  
*.VC.db  
*.VC.opendb  
.vsconfig  

# Precompiled Assets  
SourceArt/**/*.png  
SourceArt/**/*.tga  

# Binary Files  
Binaries/*  
Plugins/**/Binaries/*  

# Builds  
Build/*  

# Whitelist PakBlacklist-<BuildConfiguration>.txt files  
!Build/*/  
Build/*/**  
!Build/*/PakBlacklist*.txt  

# Don't ignore icon files in Build  
!Build/**/*.ico  

# Built data for maps  
*_BuiltData.uasset  

# Configuration files generated by the Editor  
Saved/*  

# Compiled source files for the engine to use  
Intermediate/*  
Plugins/**/Intermediate/*  

# Cache files for the editor to use  
DerivedDataCache/*  

Note that this file would only work if the Git Repo were initialized in the same folder as these folders above, and not a level above them, otherwise you would have to add the parent directory to navigate to them.

So, after you made an ignore file, let's test to see that it's working. Add another media file with the same extension type, which should also be listed in the git ignore, and if done correctly the git add . command will NOT add the new image. If it does add it, then you've not made your ignore file correctly.

Once we've managed to stop ourselves from adding the binary files, we can move on to the next step, removing the one we already added earlier! Using git rm "file.jpg" will remove "file.jpg" from the git! And also the repo! And in fact your entire computer! Wait, huh? Oh... Well, I guess if we wanted to remove it from the remote repo but not the local one then we would have needed to use git rm --cached "file.jpg". Btw, notice I've been interchangeably using "" and '' quotes, if you ever get them mixed up at one end or you use some sort of unclosed bracket it will probably send you to the next line until you close it.

So we've added files, removed files, committed our changes with a helpful note, and everything is fine now. Except the .git file has NOT decreased in size. Like at all. It's even bigger, in fact. Fuck. There are a lot of ways to recursively remove unwanted files from the git history, but the easiest in my opinion is to make a backup, delete the .git file, git init all over again except this time your git add will follow the .gitignore properly from the start, and IF we were pushing the changes to an online repo this entire time then we would just push it again...

Oh no! We're not allowed to push this new repo to the old repo because they're not the same repo anymore...

Again, multiple solutions here, but the simplest is often the best for our purposes: git push --force should in theory overwrite the remote with the local, just be careful in a real environment that you're being open and honest with your collaborators about what happened and what went wrong, keep your backup files in case they ask for them later.

If everything went well, the new .git file should be quite small, only recording changes to the text file, useful for programmers.

Git is not made for sharing large or complicated files, but it technically can do so as long as you have permission from the git host. CodeBerg allows for 750MB, GitHub allows 1GB but only 100MB per individual file, you can also selfhost your own private git repo though which would allow you to host files in the repo exceeding such limits by far, but the size will continue multiplying as commits get made so it's still not a great idea. Generally, try to only add files for code or similar text/string based storage.

Now log into CodeBerg, create a repo, obtain the URL to push to, and follow the instructions there ONE AT A TIME:

git branch -M main  
git remote add origin '<URL>'  
git push -u origin main  

And FINALLY you can see... you're not authorized to push to this repo...? Ah, right, you're not using the Git Credential Manager and you didn't login in when you made the push command, so let's just press up on the keyboard to try that exact same push command a second time. It might open a tab in your default browser asking for permissions. Probably.

Now try making a change to that text file earlier, followed by a git commit -am 'changed text' to make sure that it's working. This time, simply type git push to update the remote repo.

At the start of every workday you use the git pull command to download changes from the online repo to your local repo so that your files and git history match.

If you and the other collaborators plan to make sweeping changes without interfering with each other's works, you can try making a new branch with git switch -c <name> where the <name> is replaced with the name of the branch without brackets.

Refer to the link near the start about combining, deleting, or overwriting branches.

If you want to download an entire branch into a whole new folder, thereby making a backup of the remote repo, then use git clone <branch> and the branch here will usually be a URL

Great! Another thing to do, is to learn about how Garbage Collection works. Except we kind of bypassed that whole frustrating process earlier by simply deleting the garbage and the entire history by replacing it with a new garbage (which is really bad practice, btw).

Oh, and you also need to find out how to deal with merge conflicts when both you and another user have made multiple commits which now need to be pushed and/or pulled. Good luck!

1
MastKalandar Moderator MastKalandar@feddit.online
Joined: 2026-04-28
#3 · Quote Reply

I'll do you one better, here is a list of tasks I want you to accomplish one at a time in order to familiarize yourself with git: understand that there are two parts to a git repo: the "remote" which is stored online such as CodeBerg or GitHub, and a "local" which exists on your computer. install a git bash console and enable the right click context for it Throughout the process please refer to...

Thanks for those directions.

2
ExtraMedicated lemmy.world ExtraMedicated@lemmy.world
Joined: 2023-06-21
#4 · Quote Reply

You might like this: https://learngitbranching.js.org/
I thought it was kinda fun.

1
MastKalandar Moderator MastKalandar@feddit.online
Joined: 2026-04-28
#5 · Quote Reply

You might like this: https://learngitbranching.js.org/ I thought it was kinda fun.

That's a lovely link, thanks 👍😊

2
Post Reply
Back to top