Photo by Praveen Thirumurugan on Unsplash
Common Git Errors and How to Fix Them.
Pushing a Folder with its Contents to an Existing Repository๐ฉ๐พโ๐ป
Table of contents
Intro
Hey there fren, welcome to my tiny corner in web3.
A little about me: I am a web3 enthusiast, and this is my first foray into writing about anything related to tech/web3 - well, if you don't count that time I started and abandoned a blog that I shall not be linking here.
sike! - you thought ๐
That blog is dead and buried.
Anyway, this article is a two for one special, what's that? You may ask. Well, I decided to write this for the following reasons;
- Documenting to help others, especially those currently participating in @WomenBuildWeb3 #30DaysofWeb3 challenge, by building a fullstack decentralised RSVP app.
- Having a reference, and using this as an opportunity to start writing consistently.
full-stack? full stack?, I don't know ๐... please tweet me your response.
Git Error and Warning Messages:
So, while working through the aforementioned curriculum, I suddenly had the idea to compile some git errors I encountered trying to push a folder and its contents to an existing repository, along with the solutions that worked for me. Mind you, these solutions worked on macOS Big Sur ๐ง.
Without further ado, let's dive in.
Error Message | Translation |
Fatal: Not possible to fast-forward, aborting | This occurs when fast-forward only option is enabled while running the git pull command, and there is another commit in the destination branch that's not contained in the current branch to be merged. For this error to be averted, fast-forward requires your current branch has not diverged from the destination branch. |
Solution๐ก:
git pull --rebase
Simply put, the git pull --rebase command searches for your local commits in your current branch, and compares them with the commits in the destination branch from an earlier fetch. Thereafter, picking a starting point for rebase, then merging the changes from the destination branch with your current branch to maintain a linear and clean history.
Whether this is dangerous or not depends. Read more here and here on git pull --rebase and when not to use it.
Warning Message | Translation |
You've added another git repository inside your current repository. Clones of the outer repository will not contain the contents of the embedded repository and will not know how to obtain it. | Git returns this message in the terminal when you run the git push command to upload a folder from a cloned repository in your current branch, to the destination branch. |
Now, assuming you wanted to create a submodule or added the git repository to your current repository in error - then, you may run the commands below for each case, respectively.
git submodule add <url> <folder name>
git rm --cached <folder name>
Unfortunately, the above was not the case for me, so I took the steps below to resolve the issue.
Solution๐ก:
- Delete .git file within the folder you are trying to commit to the existing repository in your root folder for your project, then check if the folder and its content are currently tracked by running the command below:
git status
- Then, run the command below to unstage the folder and its contents, but if you get an error - try adding the -f flag before running the command.
Note: Save the folder and its content elsewhere to avoid irreversible changes before running the command below. You may use the -f flag if the first command does not remove the folder from the index.
git rm --cached <folder name>
git rm --cached -f <folder name>
- Check the status of the folder again with git status to ensure the folder and its contents have been unstaged and that you are in the correct branch, using git branch.
- Finish up and commit your folder to the existing repo in the root directory of your project by using the following commands:
git add .
git commit -m "Initial commit"
git push
PS: If you see any file(s) you do not want added and committed to the existing repo then run this command to unstage the(se) file(s):
git restore --staged <file name>
If there are multiple files, type their names with spaces between like so:
git restore --staged fileA fileB fileC
And that's it!๐
Outro
Well done, you! for getting to the end of this article. Was it helpful?, please let me know in the comments below. To keep up with my web3 journey learning solidity, follow and tweet me here.