Git commands Flashcards
Stage file README.txt for commit
git add README.txt
Commit all staged files
git commit
Commit all staged files with the message “Message”
git commit -m “Message”
Commit all files
git commit -a
Commit all files with the message “Message”
git commit -a -m “Message”
Set your name to “Name”
git config –global user.name “Name”
Set your email to Name@mail.com
git config –global user.email Name@mail.com
Initialize a new repository in the current directory
git init
Show the commit history of the current repository
git log
Show all unstaged changes to the repository
git diff
Show all staged changes to the repository
git diff –staged
Show all unstaged changes to the file README.txt
git diff README.txt
Show all staged changes to the file README.txt
git diff –staged README.txt
Stage all files for commit
git add –all
Get the status of all files in the current directory (which are tracked, changed, staged etc.)
git status
Commit the files README.txt and LICENSE.txt
git commit README.txt LICENSE.txt
Commit all .txt files in the project
git commit “*.txt”
Stage all .txt files in the current directory for commit
git add *.txt
Stage the directory src/ for commit
git add src/
Unstage README.txt
git reset HEAD README.txt
Undo the last commit and move all changed files back to staging
git reset –soft HEAD^
Completely undo the last 2 commits
git reset –hard HEAD^^
Add all staged changes to the last commit with the message “Message”
git commit –amend -m “Message”
Link the current repository to the remote repository https://github.com/Name/test.git and refer to it as origin
git remote add origin https://github.com/Name/test.git
Show all remote repositories
git remote -v
Push the main branch to the remote repository known as origin
git push origin main
Pull from the remote repository known as origin
git pull origin
Remove the remote known as origin
git remote rm origin
Clone the remote repository https://github.com/Name/test.git into the current directory
git clone https://github.com/Name/test.git
Clone the remote repository https://github.com/Name/test.git into the current directory under the name Name
git clone https://github.com/Name/test.git Name