Skip to main content

Update a git feature branch to the latest branch (master)

In our projects, team members frequently generate new Git branches linked to the same Jira number, resulting in cluttered and disorganised structures that can pose challenges for both current and future developers. For instance:

Jira: ABC-123

Ticket work: Reformat headers

Over time, these branches accumulate and become disorganised, resulting in names like:

ABC-123-reformat-headers

ABC-123-format-headers

ABC-123-format-header

Git changing local and remote branch name

Something I haven't had to do in a while is to change the name of a Git branch both local and remote.

 

Steps to renaming a branch

Rename your local branch:

If you are on the branch you want to rename:

git branch -m new-name

Whereas, if you're on a different branch:

error: pathspec did not match any file(s) known to git

Post creating a new branch in the repo, next step was to run the checkout command locally.  On my local environment I ran the following command

git checkout {branch-name}

However, the response was

error: pathspec '{branch-name}' did not match any file(s) known to git

 

how to solve - git response 'not something we can merge'

I'm in an environment where the default branch is staging and I'm attempting to run a git merge.  However, in actioning this command, I'm been greeted with the following response 'not something we can merge'

❯ git merge origin/{branch}
merge: origin/{branch} - not something we can merge

To resolve this, first I attempted to do a git checkout to the branch

git remove files from being tracked

How do you remove a file from git?

Use the command (rm) to remove files from your local git repository

git rm --cached

It's important to note the --cached flag deletes the file from your git repository, it becomes an untracked file in your project folder.  For the change(s) to kick in, you need to commit the changes.

How to move your Git repo to another location

Moving a Git repo due to a change of agencies

 

Steps to change the repo:

1. Create a temporary directory

Create a temporary directory obviously where your other sites are located locally.  For me, this is in the Sites directory.

mkdir temp-dir

 

2. Clone

Begin by cloning the current repo in the directory generated above

What the following git commands do...

git reset, git revert, and git cherry-pick are three Git commands used for different purposes related to managing your version control history. Here's a brief overview of each command:

git reset
git revert
git cherry-pick

 

How to synchronize two remote Git repositories

Currently, I have a situation where I have two repositories.  The first is where I've held the code since the beginning.  The second has come on board recently and is the client repo.  However, rather than shut the original down, I want to keep both running with the same code.  How do I synchronise them so that they contain the same thing?

How to remove .DS_Store from your git repo

Working from the bases that .DS_Store has not been added to your git repository, then you can add it to your .gitignore file.

touch .gitignore

In the .gitignore file add the following

# Hide the DS_Store files
**/.DS_Store

However, if it's already there, then in Terminal you will need to write:

Subscribe to Git