Paul Underwood
PaulundSoftware Engineer
2021-10-04 RSS Feed

Git

ssh -T [email protected] # Test Connection
git init # Initialise Git

git add <file name> # Add Files To Git
git branch -a --merged # List merged branches
git branch -d <branch-name> # Delete local branch
git branch --list # List all branches
git commit -m "Commit message" # Commit changes
git checkout <branch-name> # Checkout branch
git checkout -b <branch-name> # Creates and checkouts the new branch
git checkout --track <origin/branch-name> # Fetch and create new branch
git clone <repo-url> # Clone a Repo
git fetch origin # Fetching from remote

git log # Logs in Current Branch
git log -n 5 # Last 5 commits
git log --oneline # One line commit message
git log branch1..branch2 # Commits between branch1 and branch2
git log branch1 ^branch2 # Commits in branch1 that are not in branch2
git log -p filename # Commits that changed filename
git log --oneline | grep "Text to search" # Search for text in commit message
git log --oneline --decorate --graph --all # Show all branches in graph
git log --author="Author Name" # Show commits by author
git log --after="2014-7-1" --before="2014-7-4" # Show commits between dates
git log --grep="Text to search" # Search for text in commit message
git log --stat # Show stats of changes in commit
git log --since="2 weeks ago" # Show commits in last 2 weeks
git log --since="1 month 2 weeks 3 days 2 hours 30 minutes 59 seconds ago" # Show commits in last 1 month 2 weeks 3 days 2 hours 30 minutes 59 seconds
git log --until="2014-7-1" # Show commits until date
git log --until="today" # Show commits until today

git merge <branch-name> # Merge branch into current branch
git merge --abort # Abort merge
git merge --continue # Continue merge after resolving conflicts
git merge --no-ff <branch-name> # Merge branch into current branch without fast forward
git merge --squash <branch-name> # Merge branch into current branch with squash

git pull # Pull Latest Changes
git push -u origin master # Push Changes
git push origin <branch-name> --set-upstream # Set upstream branch on remote repository
git push origin --delete <branch-name> # Delete remote branch
git remote add origin <Url to repo> # Add remote origin
git reset --hard # Reset current changes
git reset --hard <commit-id> # Undo commit

# Submodules
git submodule add <url> <path> # Add submodule
git submodule init # Initialize submodule
git submodule update # Update submodule
git submodule foreach git pull origin master # Pull latest changes for all submodules
git submodule foreach git checkout master # Checkout master branch for all submodules

# Stash
git stash # Stash changes
git stash list # List stashes
git stash apply # Apply stash
git stash drop # Delete stash
git stash pop # Apply and delete stash
git stash clear # Delete all stashes

git status # View Changes

git revert <commit-id> # Revert commit
git revert <commit-id> --no-commit # Revert commit without commit
git revert <commit-id> --no-edit # Revert commit without opening editor

# Tags
git tag <tag name> # Create tag
git tag -l # List tags
git tag -d <tag name> # Delete local tag
git push --delete origin <tag name> # Delete remote tag
git push origin --tags # Push all tags