Home / Tutorials Home
Git Examples
Here are some Git command examples
mkdir project1 # Creates a new directory named "project1"
cd project1 # Enters the "project1" directory
git init # Initializes an empty Git repository in the current directory
git config --global user.name "Your Name" # Set your username
git config --global user.email "your@email.com" # Set your email
echo "Hello, Git!" > hello.txt # Creates a file named "hello.txt" and adds content
git status # Checks the current status of your Git repository
git add hello.txt # Stages the changes made to hello.txt for commit
git commit -m "Add a greeting message" # Commits the staged changes with a message
For instance, if you have a repository on GitHub:
git remote add origin <repository_URL> # Connects your local repo to a remote repo
git push -u origin master # Pushes committed changes to the "master" branch of the remote repo
These commands demonstrate the basic workflow of creating a Git repository, adding content, committing changes, and pushing them to a remote repository. You can replace <repository_URL>
with the actual URL of your remote repository.