This content originally appeared on DEV Community and was authored by Devtonight
This question explains how to set up a local Git repository and push it to Github.
Git Installation
Windows Installation
- Go to https://git-scm.com/downloads and click “Download For Windows”.
- Select 32 bit or 64 bit according to your PC architecture.
- Open the downloaded
exe
file.
The installation wizard will ask for basic information like the installation path, whether create desktop icons or not etc. You can leave them all in their default settings or make necessary changes and press “Next”. Ultimately, you will see the “Install” button at the end and it will begin the installation process.
Linux Installation
Open a terminal window and enter the following command, it will update the local software repository.
sudo apt-get update
Then install Git using the following command.
sudo apt-get install git
Mac Installation
-
Install
Homebrew
if not already installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Install Git
brew install git
Visit https://git-scm.com/downloads and click “Download for Mac” for more information and alternative installation methods.
Check The Installation
Run the following command, it should display the installed Git version.
git --version
Create Your First Git Repository
First, create a new directory.
mkdir hello-git
Go into that directory.
cd hello-git
Initialize a new local Git repository
git init
Create a file called hello-git.html
or otherwise, you can add your code files.
touch hello-git.html
Add some content into hello-git.html
file and check the status of the repository. It will display the changed files.
git status
Add hello-git.html
to the repository.
git add hello-git.html
If you have multiple files, you can add them all by using -A
flag.
git add -A
Commit changes with a short and meaningful message like what you did in the commit.
git commit -m "hello-git.txt added"
Push To Github
Set the Github username. Your username is the part after the 3rd forward-slash (/
) of your profile URL. For example, in https://github.com/bitcoin
, bitcoin
is the username.
git config --global user.username your_github_username
Create a new repository in Github by visiting https://github.com/new.
Link the Github remote repository to the local repository.
git remote add origin https://github.com/your_github_username/hello-git.git
Push local repository to Github repository.
git push origin master
Feel free to visit devtonight.com for more related content.
This content originally appeared on DEV Community and was authored by Devtonight
Devtonight | Sciencx (2021-12-14T17:22:32+00:00) How To Install Git And Push Codes To Github. Retrieved from https://www.scien.cx/2021/12/14/how-to-install-git-and-push-codes-to-github/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.