Clarification on the git commands for contributing

I waiting on approval for a PR for some typos in the Beta version of the Responsive Web Design course. I followed the steps in how-to-setup-freecodecamp-locally.md document. I also got a response from Jessica Wilkins but I’ve been messaging her back and forth and I don’t want to continue bothering her.

I created a CodePen to compare the 2 sets of commands and here is an image as well:

I followed all the steps in the section labeled “First set of commands” and it appears everything went fine. However, Jessica mentioned being careful about using git reset --hard.

For the git commands that I colored blue, are they only for when you first clone the repo, or should I repeatedly use them? I know that git diff upstream/main is optional, so that can be ignored.

Now that I have cloned the repo, can I use the Second set of commands which Jessica gave me? In time I will understand all the commands, but in the time being, I would like to have a list of the commands I need to do to contribute.

Git can be confusing in the beginning, for sure. Later on, there are advanced git things that can also be very confusing, for sure.

These commands are not monolithic, inscrutable texts - these are commands with meanings.

Comparing your first ones: git clone --depth=1 https_url and git clone https_url, again, just understand the difference. I’ve never used the “depth” flag before. So, I would google “git clone” and I get lead here. In there, I can read:

-- depth <depth>

Create a shallow clone with a history truncated to the specified number of commits. Implies --single-branch unless --no-single-branch is given to fetch the histories near the tips of all branches. If you want to clone submodules shallowly, also pass --shallow-submodules .

OK, so it is telling you that instead of downloading the entire commit history, you can specify how deep to go.

I would work through it like that. Understand what it is saying.

Jessica mentioned being careful about using git reset --hard .

Yes, messing with the git history is always tough. The “hard” flag will also remove any changes you made since the commit to which you are resetting. It’s fine if that is what you want, but be careful.

For the git commands that I colored blue, are they only for when you first clone the repo, or should I repeatedly use them?

Again, it depends. They could all be used at any point, depending on what you want.

Now that I have cloned the repo, can I use the Second set of commands which Jessica gave me?

Sure, I guess, depending on what you want.

In time I will understand all the commands, but in the time being, I would like to have a list of the commands I need to do to contribute.

I would not recommend using a git command unless you know what it is doing. You can do a lot of damage with sloppy git commands. I’m not saying you need to master git before proceeding, but at least understand what you are doing. Don’t just cut and paste git commands and hope for the best.

There are plenty of videos out there. There is also a great book called Mastering Git. It is a free ebook. It gets pretty advanced, but the first chapters go through a lot of interesting technical details.

1 Like

Thanks! I’ve watched a lot of videos and read a lot of articles.

I should not have highlighted the --depth=1 because I did read about it on the md file where I found all those steps: --depth=1 creates a shallow clone of your fork, with only the most recent history/commit.

The main confusion for me is the 1st two blue commands and the difference of upstream in the remote add line and then for the push command in the second set of commands, with --set-upstream where the push in the 1st set did not use that in the push.

I’ll look into each command to see what is going on.

Once you’re set up with a local repository, you’ll mostly just be doing

git  pull

To update your local main/master

git checkout

To create/switch to your branch

git add

To stage changes

git commit

To create a commit from staged changes

git push

To update your remote branch

The bit about set-upstream is something you’ll have to do when you do the first push from a new branch, to create the branch on the remote repository. I am lazy, so I never type it. When I do a first push I let the shell prompt me to do it.

The “shell”? Do you mean power shell? I do all of my commands from within VS Code.

I have the following message in my clone of freeCodeCamp:

This branch is 3 commits behind freeCodeCamp:main.

I keep forgetting to switch back to main, but I did git fetch upstream from my branch then git push origin main and refreshed my repo but the message is still there. So then I switched to main and the fetch from there returned this error:

fatal: ‘upsteam’ does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I don’t want to click the fetch upstream link in my clone repo on GitHub. I’m getting confused with some of the commands. I’m watching the video from FCC titled " Git and GitHub for Beginners - Crash Course" for the second time. Hopefully, the 2nd time will clear things up for me.

Sounds like you never set anything as ‘upstream’.

Did you check the configuration as per the setup instructions?

Ensure the configuration looks correct:

git remote -v

The output should look something like below (replacing YOUR_USER_NAME with your GitHub username):

origin    https://github.com/YOUR_USER_NAME/freeCodeCamp.git (fetch)
origin    https://github.com/YOUR_USER_NAME/freeCodeCamp.git (push)
upstream    https://github.com/freeCodeCamp/freeCodeCamp.git (fetch)
upstream    https://github.com/freeCodeCamp/freeCodeCamp.git (push)

Yes, I checked that and that is what I saw.

You are getting that in the same branch that you are getting the error “fatal: ‘upsteam’ does not appear to be a git repository”?

I can’t remember since I’ve had a lot of git issues since then.

The error suggests there might have been a typo in used command - upsteam instead of upstream

1 Like

Good catch!

I hope no one is keeping a running count of my typos!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.