# Rename a branch and delete remote old branch
git checkout <old_name>
git branch -m <new_name>
git push origin -u <new_name> # If the old branch is on remote
git push origin --delete <old_name> # If the old branch is on remote
# Revert to the state just before the last commit
git reset HEAD^
git reset 'HEAD@{1}' # revert last one
# Show number of modified lines per file
git diff --numstat
# Print last commit message
git log -1 --pretty=%B
# Get specific remote branch
git fetch origin <branch_name>
# Pull and resolve conflicts with rebase
# https://stackoverflow.com/questions/35025587/git-pull-and-resolve-conflicts
git checkout master
git pull origin master
git checkout feature-branch
git pull origin feature-branch
git rebase origin/master
git add <file-name> # after solving conflicts
git rebase --continue # after solving conflicts and staging changes
git push --force origin feature-branch
# Avoiding rebase hell, squash before rebase
# https://blog.oddbit.com/post/2019-06-17-avoid-rebase-hell-squashing-wi/
git checkout -b tmp-branch master # create a temporal branch from master
git merge --squash feature-branch # resolve conflicts
git commit -m "message"
git checkout feature-branch
git reset --hard tmp-branch
git push --force origin feature-branch
git branch -D tmp-branch # delete temporal branch
# Merge devel into main
git checkout devel
git pull origin devel
git checkout main
git pull origin main
git merge devel
git push origin main
# Revert merge
git checkout main
git pull origin main
git revert -m 1 <merge_commit_hash> # find the commit hash in github: branch -> commits -> copy hash of merge
git push origin main --force # If you can't force push, create a pull request
# Reset branch to remote state
git checkout my-branch
git fetch origin && git reset --hard origin/my-branch && git clean -f -d
# Clean the local repo
git gc --prune=now
git fetch origin --prune # deletes the refs to the branches that don't exist on the remote
git clean -fd # Remove untracked files and directories
# Restore (revert) changes not staged
# https://git-scm.com/docs/git-restore
git restore . # restores all files in current dir (recursively)
# Differences between branches
git diff devel..feature-branch
git diff devel...HEAD # between devel and current branch
# Discard unstaged changes in Git?
git restore .Your commits only count as contributions if you author those commits using an email address that is associated with your GitHub account. A commit will only count as a contribution if one of the following is true:
- You are a collaborator on the repository or are a member of the organization that owns the repository.
- You have forked the repository.
- You have opened a pull request or issue in the repository.
- You have starred the repository.
We recommend starring any repositories you contribute to. That way, your commits to those repositories will remain in your contributions graph even if you leave the organization that owns the repository or delete your fork of the repository.
GitHub hides commits in private repositories from your contributions graph by default. Learn how to display this activity to fill in your graph with as many green squares as possible.
The contributions data for each repository is recalculated every time someone pushes to that repository. This can take some time, so if you made a commit recently, you may need to wait a few hours before the contribution shows up in your graph.