Git is a version control system that helps in tracking changes in files, coordinating work between multiple people, and working on different versions of files. It is a command-line tool that can be used to manage and track changes in code and other files.
git config
sets up your email address and name so changes can be attributed to you.
$ git config --global user.email "you@example.com"
$ git config --global user.name "Your Name"
-
git init
creates a new repository for you to start tracking changes in your code.$ git init my-project
-
git clone
creates a local copy of a remote repository, allowing you to work on the code locally.$ git clone <https://github.com/user/repo.git>
-
git add
adds changes to the staging area so that they can be committed to the repository.$ git add README.md
-
git commit
saves the changes you have made to the repository, along with a commit message describing the changes.git commit -am
adds and commits changes with a message in one step.
$ git commit -m "Add README.md"
-
git status
shows the current status of the repository, including any changes that have been made since the last commit.$ git status
-
git log
displays the commit history of the repository, including the author, date, and commit message for each commit.$ git log
-
git push
pushes the changes you have made to a remote repository, such as one hosted on a Git hosting service like GitHub or GitLab.$ git push origin
-
git pull
fetches changes from a remote repository and merges them with your local repository.$ git pull origin
To set up a new coding project and add a README.md to a GitHub repository and push it, follow these steps:
-
Create a new project directory on your local machine.
$ mkdir my-project
-
Navigate to the new project directory.
$ cd my-project
-
Initialize the directory as a Git repository.
$ git init
-
Create a new README.md file in the project directory.
$ touch README.md
-
Add some content to the README.md file.
$ echo "Hello world" >> README.md
-
Add the README.md file to the staging area.
$ git add README.md
-
Commit the changes to the repository with a commit message.
$ git commit -m "Add README.md"
-
Create a new repository on GitHub.
-
Add the remote repository URL as a remote in your local repository.
$ git remote add origin <https://github.com/user/repo.git>
-
Push the local repository to the remote repository on GitHub.
$ git push -u origin main