Lessons 267, 268 & 269 – Complete 2020 Web Development Bootcamp

Lesson 267 – Gitignore

The first step in using gitignore is to create a hidden .gitignore file in your directory. To do that you cd to the directory you are using and then type –

touch .gitignore

The next step is to open the .gitignore file by typing –

open .gitignore

Once the .gitignore file is opened in the text editor, you add the files that you want git to ignore.

If you don’t add anything to the .gitignore file then git will add and commit all the files in your project directory.

So for example if you have a file called “secrets.txt” in which you have passwords and api keys, that file will be added to the staging area and will be committed unless you add it to the .gitignore file.

If you have run –

git add .

and then discover that you didn’t add your secrets.txt file to .gitignore, you can take your files out of the staging area by running –

git rm --cached -r .

Inside the .gitignore file, you type each file name you want git to ignore on a separate line.

You can add comments using the # sign. So for example –

#file with passwords and API keys
secrets.txt

You can also use wildcards. If you use the * sign followed by the file extension, all files with that extension will be ignored. So –

*.txt

will ignore all files with the .txt extension.

The site – https://github.com/github/gitignore – is a github repository of pre-built .gitignore file for various programming languages.

Lesson 268 – Cloning

To copy the files on a remote repository and pull them down to your local machine you use the command –

git clone

Lesson 269 – Branching and Merging

To create a new git branch, you use this command –

git branch alien-plot

This will create a new git branch labelled “alien-plot”.

To see how many branches you have, you use the command –

git branch

To switch to a branch you use the git checkout command with the branch name. So to switch to the alien-plot branch, you would use this command –

git checkout alien-plot

To go back to the master branch, you use the command –

git checkout master

To merge changes made on the branch back into the master, you first go back to the master branch using the command –

git checkout master

You then use the git merge command and specify the branch name. So to merge the alien-plot branch into the master branch, you would use this command –

git merge alien-plot