Submit

How to stop password prompts on any git command on macOS?

· Mandeep Singh · Solving Mistories

Ever since macOS 10.12 Sierra update for ssh, people have been facing issue with git prompting for ssh passphrase every time you run any git command.

Although, It’s been a long time since the release still I see many developers asking me this, so I thought to write a simple solution here.

What you need to do?

For macOS 10.12 Sierra ssh-add -K needs to be run after every reboot. To avoid this create ~/.ssh/config with this content.

Host *
    UseKeychain yes

That is all you need to do and you are good to go.

How to stage changes one by one after review in git?

· Origin Twitter · Solving Mistories

When working on your code there are some situations when you might have to push a simple fix or a piece a code. Normally, it is recommended to create a new fix branch from your master and push it back but some times we kind of go lazzy. In those movments I simply do the changes and add them one by one using the following command:

$ git add -p

I believe it’s worth menthioning how I got to know about this nice little helper.

add

How to remove staged changes from git

· Origin Unknown · Solving Mistories

To remove your stagged changes or to undo your last git add command you can simply use git reset. Running the below command will simply remove all files from your staging area:

$ git reset

In case you want to remove only a specifc file(s) than you can mention the name of file(s), like this:

# To remove a single file
$ git reset filename.ext

# You can also remove bunch of files using simple rejex expressions
$ git reset content/*.png

How to sync my commits with multiple repositories

· Origin StackOverflow · Solving Mistories

There are many ways of doing this, some include custom scripts, app and even some paid services. We will do this using the simplest way of having multiple urls for a single remote.

Let's say you have added your original remote like this:

$ git remote add origin origin-host:path/to/project.git

What many people don't know is that you have an option to added multiple hosts for the same remote. You can do this by simply adding your second host to same remote like this:

$ git remote set-url --add origin second-host:path/to/project.git

You can do this any number of times you want can have any number of hosts..

$ git remote set-url --add origin third-host:path/to/project.git
$ git remote set-url --add origin fourth-host:path/to/project.git
$ git remote set-url --add origin fiveth-host:path/to/project.git

Your config file will look something like this:

[remote "origin"]
    url = origin-host:path/to/project.git
    url = second-host:path/to/project.git
    url = third-host:path/to/project.git

Now you can simply push your changes with a single command and they will be synced to all repositories.

$ git push origin {branch name}

Want to Contribute?

Send me an Email, ping me on Twitter or submit a pull request on Github.

Sign up below to receive updates, tips and more handy tutorials when git screws up. It’s good stuff & I don’t spam.