Nono.MA

FEBRUARY 23, 2023

Here's how to list the commits that happened between two tags.

git log --pretty=oneline 0.8.0...0.9.0

The two tags—in this case, 0.8.0 and 0.9.0—need to exist.

You can list existing tags in a repository as below.

git tag

SEPTEMBER 2, 2022

Here's how to remove a remote Git branch without using an app or a website user interface, say, GitHub or GitLab.

# Delete a remote Git Branch (assuming your remote is called origin)
git push origin --delete your-branch-name
# To bitbucket.org:nonoesp/some-repo.git
#  - [deleted]         your-branch-name

Remember that you will also have to delete the Git branch from your local repository as follows.

# Delete a local branch
# -d is a shorthand for --delete
git branch -d your-branch-name
# Deleted branch your-branch-name (was f9b622c).

# Force delete a local branch (regardless of the branch merge status)
# -D is a shorthand for --delete --force
git branch -D your-branch-name
# Deleted branch your-branch-name (was f9b622c).

SEPTEMBER 1, 2022

Here's how to remove a local Git branch.

# Delete a local branch
# -d is a shorthand for --delete
git branch -d your-branch-name
# Deleted branch your-branch-name (was f9b622c).

# Force delete a local branch (regardless of the branch merge status)
# -D is a shorthand for --delete --force
git branch -D your-branch-name
# Deleted branch your-branch-name (was f9b622c).

Remember that you will also have to delete the Git branch from your remote repository as a separate step.

Here's how to remove a remote Git branch without using an app or a website user interface, say, GitHub or GitLab.

# Delete a remote Git Branch (assuming your remote is called origin)
git push origin --delete your-branch-name
# To bitbucket.org:nonoesp/some-repo.git
#  - [deleted]         your-branch-name

APRIL 2, 2022

I was getting this error when trying to git add and git commit code changes in my repository.

fatal: Unable to create '.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

Simply removing the .git/index.lock file made everything go back to normal.

rm .git/index.lock

Nothing broke and I could immediately add and commit new files.

APRIL 20, 2021

cd /path/to/repo.git
sudo chgrp -R {groupname} .
sudo chmod -R g+rwX .
find . -type d -exec chmod g+s '{}' +

Source

FEBRUARY 10, 2020

Let say you stage all your Git changes and then commit them.

git add --all
git commit -m "Edit REDME.md"

There's a typo on REDME — should read README — and we want to "amend" this error.

git commit --amend

The commit --amend command lets you edit the commit message in the vim editor.

You can also change the message by specifying the new message in the command line with the -m argument.

git commit --amend -m "Edit README.md"

As the commit message is part of the commit itself, editing the message alters the commit hash, which means that if you've already pushed a commit to a remote, the remote won't let you push the new edit directly. But you can force that to happen.

git push --force branch-name

FEBRUARY 5, 2020

git push origin $(git branch | grep \* | cut -d ' ' -f2)

AUGUST 21, 2019

# Get name of Git's current branch and push changes to origin
git push origin $(git branch | grep \* | cut -d ' ' -f2)

I use a text expander to expand gpp to this command whenever I'm on Terminal. Instead of expanding to git push origin master this command will push to whatever branch you are in.

# Get name of Git's current branch
git branch | grep \* | cut -d ' ' -f2

MARCH 17, 2019

open $(git remote get-url origin)

Note that this will only work when the Git repository has been cloned via HTTPS and not SSH.

NOVEMBER 20, 2018

You can set Git to assume certain files haven't changed even when they have (without adding them to your .gitignore file). This way, it won't track changes to make to one (or multiple) files.

Tell Git to assume a file is unchanged

git update-index --assume-unchanged file

Tell Git not to assume a file is unchanged anymore

After this command is run, the repository continues tracking the file. It might have changes that git will want to commit.

git update-index --no-assume-unchanged file

Roll back the changes you made while the file was --assume-unchanged

In case you made changes while --assume-unchanged was on and don't want to keep the changes on the file: Roll-back to where the repository is when you want to pull or push changes.

git checkout -- file

Want to see older publications? Visit the archive.

Listen to Getting Simple .