🐙 Git Basic Commands Cheat Sheet

🚀 First Git Commands

git init
git add .
git commit -m 'initial commit'
git remote add origin https://github.com/user_name/test.git
git push -u origin master

📦 Basic Commands

Clone a repository to your local machine

git clone repository_url

Add a file to the local repository

git add .

Commit changes to the local repository

git commit -m 'initial commit'

Push changes to a remote repository

git push origin main

Push changes to the remote repository (subsequent times)

git push

Commit all modified files without using git add

git commit -a -m 'commit all edited files'

View current changes

git status

🌿 Working with Branches

Show current branch and all branches (-a for all)

git branch -a

Create a new branch named newbranch

git branch newbranch

Switch to a branch

git checkout newbranch

Push a branch to the remote repository

git push origin newbranch

Delete a branch locally

git branch -d newbranch

Delete a branch remotely

git push origin --delete newbranch

Undo the last commit but keep changes

git reset HEAD~

Undo the last commit and discard changes

git reset --hard HEAD~

git reset moves HEAD to a specified state.
HEAD~ means "one commit before the current HEAD."


📤 Push to Multiple Repositories

Create a new remote (example: "all")

git remote add "all" git@github.com:username/my-repo.git

Add multiple push URLs to it

git remote set-url --add --push "all" git@github.com:username/my-repo.git
git remote set-url --add --push "all" git@bitbucket.org:username/my-repo.git

Push to both repositories at once

git push all

🗑 Apply .gitignore Changes to Existing Repo

Remove all files from the index (respecting .gitignore)

git rm -r --cached .
git add .
git commit -m 'Removed all files that are in the .gitignore'
git push origin master

🚀 Explore more guides on our blog 👉 blog.1it.pro
📧 Contact us: admin@1it.pro for expert IT guidance.
🌐 Explore more: Visit 1it.pro for top-tier IT solutions.

UA EN RU

Зв'язатися з нами

Telegram Email