Skip to content

Instantly share code, notes, and snippets.

@derhuerst
Last active November 14, 2024 12:19
Show Gist options
  • Save derhuerst/1b15ff4652a867391f03 to your computer and use it in GitHub Desktop.
Save derhuerst/1b15ff4652a867391f03 to your computer and use it in GitHub Desktop.
Installing Git on Linux, Mac OS X and Windows

Installing Git on Linux

Determine on which Linux distribution your system is based on. See List of Linux distributions – Wikipedia for a list. Most Linux systems – including Ubuntu – are Debian-based.

Debian-based linux systems

Open a terminal window. Copy & paste the following into the terminal window and hit Return. You may be prompted to enter your password.

sudo apt update
sudo apt upgrade
sudo apt install git

You can use Git now.

Red Hat-based linux systems

Open a terminal. Copy & paste the following into the terminal window and hit Return. You may be prompted to enter your password.

sudo yum upgrade
sudo yum install git

You can use Git now.

Installing Git on a Mac

Open a terminal window.

Step 1 – Install Homebrew

Homebrew […] simplifies the installation of software on the Mac OS X operating system.

Homebrew – Wikipedia

Copy & paste the following into the terminal window and hit Return.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew doctor

You will be offered to install the Command Line Developer Tools from Apple. Confirm by clicking Install. After the installation finished, continue installing Homebrew by hitting Return again.

Step 2 – Install Git

Copy & paste the following into the terminal window and hit Return.

brew install git

You can use Git now.

Installing Git on Windows

  1. Download Git from Git for Windows and install it.
@CyberChick111
Copy link

@mithlesh4257 try
sudo apt-get update then sudo apt-get upgrade followed by sudo apt-get install git

This one worked!! Thanks

@Phontera
Copy link

It worked! Thank you.

@gprakarsh
Copy link

The link for the Mac Download is outdated. This is the one that should be used -
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

@ASCassinda
Copy link

buhhiih

@Cyber-Guy24
Copy link

Thanks mark-nirdesh that worked for me as well

@wajeehas
Copy link

I have tried installing homebrew via mac os terminal, but it keeps asking me for a password. does anyone know which password this is? it comes up as a key sign.
Screenshot 2020-09-13 at 21 56 42

@derhuerst
Copy link
Author

I have tried installing homebrew via mac os terminal, but it keeps asking me for a password. does anyone know which password this is? it comes up as a key sign.

It looks like it uses sudo to install itself to a specific location on your computer; sudo requires your password. You will have to put your macOS user's password.

This is badly designed, it should actually explain why it is using sudo.

@mahfudivan
Copy link

I have tried installing homebrew via mac os terminal, but it keeps asking me for a password. does anyone know which password this is? it comes up as a key sign.
Screenshot 2020-09-13 at 21 56 42

your laptop password, I use a macbook, I also enter my laptop password

@temoke-levelops
Copy link

Works for Mac! Where do I give thumbs up?

@mavaddat
Copy link

I need help.
I'm using Kali Linux.

why use shell ?
use sudo apt-get install git

They (incorrectly) copied the entire markdown-laden code-block and pasted that into the bash terminal, which of course bash cannot interpret as a command. Do not paste the markdown (e.g., ```shell) into bash — that part is just for formatting the code on GitHub.

@AssefaDemeke12
Copy link

git hub setup for linux

@Poojap19create
Copy link

I am getting an error while installing git for UBUNTU Can anybody help please
Screenshot from 2021-03-26 12-24-23

@mavaddat
Copy link

mavaddat commented Mar 29, 2021

I am getting an error while installing git for UBUNTU Can anybody help please

Your Ubuntu version is no longer maintained. You need to update your distribution to a version that is within its support lifetime. For example, try using this upgrade combination:

sudo apt update
sudo apt -y upgrade && sudo apt autoremove -y
sudo apt-get -y dist-upgrade

If that doesn't work, then try re-building your sources.list using this tool: Ubuntu Sources List Generator

Command Meaning
apt update Used to re-synchronize the package index files from their sources. The indexes of available packages are fetched from the location(s) specified in /etc/apt/sources.list(5). An update should always be performed before an upgrade or dist-upgrade.
apt upgrade Used to install the newest versions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list(5). Packages currently installed with new versions available are retrieved and upgraded; under no circumstances are currently installed packages removed, nor are packages that are not already installed retrieved and installed. New versions of currently installed packages that cannot be upgraded without changing the install status of another package will be left at their current version. An update must be performed first so that apt-get knows that new versions of packages are available.
apt-get dist-upgrade In addition to performing the function of upgrade, this option also intelligently handles changing dependencies with new versions of packages; apt-get has a "smart" conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones, if necessary.

@rachmat95
Copy link

rachmat95 commented Nov 1, 2021

sudo apt-get update then sudo apt-get upgrade followed by sudo apt-get install git

@duarteing
Copy link

when i want to send my code to my repository --> "git push -u origin main"

this appears, but why they continue ask me about password if they already not accept.
and i been trying whit ssh keys and can not do it also.

some idea...

remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/duarteing/globalduarte.github.io.git/'

@mavaddat
Copy link

mavaddat commented Feb 8, 2022

First, you need to create a personal access token (PAT). Why? The process is described here: Creating a personal access token

Using a token on the command line

Once you have a token, you can enter it instead of your password when performing Git operations over HTTPS.

For example, on the command line you would enter the following:

$ git clone https://github.com/username/repo.git
Username: your_username
Password: your_token

Personal access tokens can only be used for HTTPS Git operations. If your repository uses an SSH remote URL, you will need to switch the remote from SSH to HTTPS.

If you are not prompted for your username and password, your credentials may be cached on your computer. You can update your credentials in the Keychain to replace your old password with the token.

Instead of manually entering your PAT for every HTTPS Git operation, you can cache your PAT with a Git client. Git will temporarily store your
credentials in memory until an expiry interval has passed. You can also store the token in a plain text file that Git can read before every
request. For more information, see "Caching your GitHub credentials in Git."

@hadiheib99
Copy link

hadiheib99 commented Mar 21, 2022

Hi there,
I'm using kali linux
I still getting this error while trying to download git :
Sub-process /usr/bin/dpkg returned an error code (1)

what I have to do here??

@mavaddat
Copy link

Hi there, I'm using kali linux I still getting this error while trying to download git : Sub-process /usr/bin/dpkg returned an error code (1)

what I have to do here??

@hadiheib99 You don't mention the entire apt readout, but one of your packages may be broken.

Here are a few things you can try (run sudo apt update after each).

Method 1: Reconfigure Package Database

The first method you can try is to reconfigure the package database.
Perhaps the database got corrupted while installing a package.
Reconfiguring often fixes the problem.

sudo dpkg --configure -a

Method 2: Use force install

If a package installation was interrupted previously, you may try to do
a force install.

sudo apt install -f

Method 3: Try removing the troublesome package

If it’s not an issue for you, you may try to remove the broken package
manually. Don’t do this for Linux Kernels (packages starting with
linux-).

sudo apt remove <package_name>

Method 4: Remove post info files of the troublesome package

This should be your last resort. You can try removing the files
associated to the package in question from /var/lib/dpkg/info.

You need to know a little about basic Linux commands to figure out
what’s happening and how can you use the same with your problem.

For example, you had an issue with polar-bookshelf. You would look for the
files associated with it:

ls -l /var/lib/dpkg/info | grep -i polar-bookshelf
-rw-r--r-- 1 root root 2324811 Aug 14 19:29 polar-bookshelf.list
-rw-r--r-- 1 root root 2822824 Aug 10 04:28 polar-bookshelf.md5sums
-rwxr-xr-x 1 root root     113 Aug 10 04:28 polar-bookshelf.postinst
-rwxr-xr-x 1 root root      84 Aug 10 04:28 polar-bookshelf.postrm

Now all I needed to do was to remove these files:

sudo mv /var/lib/dpkg/info/polar-bookshelf.* /tmp

Use the sudo apt update and then you should be able to install software
as usual.

@moah1387
Copy link

thank you

@waleudeclan
Copy link

I have tried installing homebrew via mac os terminal, but it keeps asking me for a password. does anyone know which password this is? it comes up as a key sign.
Screenshot 2020-09-13 at 21 56 42

its your computer's administrator password

@thebollywoodguy
Copy link

Just confirmed that macOS instructions still work ! 🗡️

@htahrawi
Copy link

It worked in Ubuntu
Thank you

Copy link

ghost commented Dec 30, 2022

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment