Lorenzo Vainigli

Software developer, passionate about programming

Git Commands

4 December 2022
  1 min.     0

Setting up

# Init a local repository
git init

# Clone a remote repository
git clone <remote_repository_url>

# Add remote to local repository
git remote add origin <remote_repository_url>

Committing

# See changes to be commit, changes not staged for commit and untracked files
git status

# See local changes not staged for commit
git diff --stat

# View commit history
git log

# Stage file for commit
git add <file>

# Unstage file from commit
git restore --staged <file>

# Committing all changes
git add *
git commit -m "Commit message"

# Undo last commit and preserve changes
$ git reset --soft HEAD~1

# Undo last commit and discard changes
$ git reset --hard HEAD~1

# Edit last commit
git commit --amend

# Push to remote repository (default branch)
git push

# Push to remote branch
git push origin <branch_name>

Branching

# List all branches
git branch

# Change branch
git checkout <branch_name>

# Create a new branch
git checkout -b <branch_name>

# Push a branch to remote repository
git push origin <branch_name>

# Rename current branch
git branch -m <new_name>

# Merge a branch into main branch
git checkout main
git merge <branch>

Tags

# Add tags to the current commit
git tag -a <tag_name> -m "Tag message"

# Show tags
git tag

# Show tag data
git show <tag_name>

# Pushing all tags to the repository
git push origin --tags

# Delete local tag
git tag -d <tag_name>

# Delete remote tag
git push --delete origin <tag_name>

# See differences between two tags
git diff tag1 tag2 --stat

Remove items

# Remove remote directory
git rm -r --cached FolderName
git commit -m "Removed folder from repository"
git push origin master

Other

# List ignored files
git status --ignored

Hi 👋, I'm Lorenzo 👨🏻‍💻

🇮🇹 Italian
💼 Software developer
🎓 Master's degree in computer science

Tech interests
🤖 Artificial intelligence
🧠 Machine learning
📊 Data Analysis
🌐 Web development
📱 Android development
Other interests
🪐 Astronomy
🇯🇵 Japanese culture
🥋 Martial arts
🎮 Videogames
📸 Photography

More about me