git init
: Suppose you have a new project directory called my_project
. You initialize a Git repository in this directory.
cd my_project
git init
git clone [url]
: You want to work on an existing project hosted on GitHub. You clone the repository to your local machine.
git clone <https://github.com/username/repo.git>
git status
: You’ve made changes to your files and want to see what’s modified.
git status
git add [file]
: You’ve created a new file index.html
and want to add it to the staging area.
git add index.html
git commit -m "[message]"
: After staging index.html
, you commit your changes with a descriptive message.
git commit -m "Add index.html with basic structure"
git diff
: You want to see what changes you’ve made to index.html
since the last commit.
git diff index.html
git log
: You want to see the history of commits.
git log
git branch
: You want to see all the branches in your repository.
git branch
git checkout [branch-name]
: You are currently on the main
branch and want to switch to the feature-branch
.
git checkout feature-branch
git merge [branch-name]
: You want to merge feature-branch
into main
.
git checkout main
git merge feature-branch
git remote -v
: You want to see the URLs of your remote repositories.
git remote -v
git fetch [remote]
: You want to fetch the latest changes from the remote repository origin
.
git fetch origin
git pull [remote]
: You want to fetch and merge changes from the remote repository origin
into your current branch.
git pull origin main
git push [remote] [branch]
: You want to push your local main
branch to the remote repository origin
.
git push origin main