git Essentials

1. git init

This command initializes a new Git repository locally in your current directory. It creates a new .git directory where all Git metadata and objects will be stored. This is the first command you run when you start tracking a project with Git.

2. git add .

This command stages all changes (files and directories) in your current directory and all subdirectories for the next commit. This includes new files, modified files, and deleted files. The . denotes “current and all subdirectories.”

3. git commit -m "Very first commit"

This command commits the staged changes to the local repository. The -m option allows you to add a commit message inline. Here, “Very first commit” is the description you’re giving to this set of changes.

4. git remote add origin https://github.com/sasinna/people-app.git

This command links your local repository to a remote repository. origin is a shorthand name you assign to the specific remote repository URL. After setting this up, origin will be used to refer to https://github.com/sasinna/people-app.git in future commands.

5. git push origin HEAD:master

This command pushes the commits from your local branch (HEAD) to the remote branch named master on the origin remote. If master does not exist on the remote, it will be created. HEAD is a reference to the last commit of the currently checked-out branch.

6. git rm -r --cached Back Up

Assuming you meant git rm -r --cached Backup, this command removes the Backup directory from the staging area (index) and from the next commit but leaves the physical files intact in your working directory. The -r stands for recursive, which is necessary for directories. The --cached option tells Git to only remove the files from the index, not the local file system.

7. git add .gitignore

This command stages the .gitignore file for the next commit. The .gitignore file is used to tell Git which files or directories to ignore and not track. Changes to this file itself need to be tracked and committed, hence the need to add and then commit it if you’ve made changes to it.

Leave a Reply

Your email address will not be published. Required fields are marked *