In this module, you'll learn about version control using Git. You'll learn how to use Git to move files from a working directory to the Git staging area and a local Git commit, and how to push local changes to make them permanent.
Git is a distributed version control system that helps you track changes in your code and collaborate with others. It was created by Linus Torvalds in 2005 for development of the Linux kernel.
git init
- Initializes a new Git repository in the current directorygit clone <url>
- Creates a copy of a remote repository on your local machinegit config --global user.name "Your Name"
- Sets your username for commitsgit config --global user.email "your.email@example.com"
- Sets your email for commitsWhen working with projects from GitHub Classroom:
git clone <copied-url>
git branch <name-of-branch>
git checkout <name-of-branch>
git clone <url>
- Downloads a repository to your local machinegit add .
- Stages all changes for commit (the .
includes all changes)git commit -m "message"
- Creates a snapshot of your staged changes with a descriptive messagegit push
- Uploads your commits to the remote repository# Clone a repository
git clone https://github.com/username/repository.git
# Create and switch to a new branch
git branch feature-branch
git checkout feature-branch
# Make changes to files...
# Stage and commit changes
git add .
git commit -m "Add new feature"
# Push changes to remote repository
git push --set-upstream origin feature-branch
# Create a pull request on GitHub
When you're on a new branch, the first time you push you may need to set your upstream:
git push --set-upstream origin <name-of-branch>
After setting the upstream once, you can simply use git push
for future pushes.
In this guided project, you'll learn how to work with Git branches, which are essential for collaborating on projects and developing features in isolation.
For sprint projects, it's recommended to: