Git Init
Table of contents
Inititating git workflow either for a new project or existing
Adding existing project to collaborate (Github)
- Create a new repository on Github, I’ll call my repository
nasigoreng
- Navigate to the working directory with command line and initialise Git:
git init -b main
- Add the files in the local repostiory, this will stage them for the first commit:
git add .
- Then commit them
git commit -m "Initial commit"
- Copy the URL of the repository you set on step 1. For example
git@github.com:jamirawan/nasigoreng.git
- Then go back to the terminal add git remote on the folder you just committed:
git remote add origin git@github.com:jamirawan/nasigoreng.git #then check the remote: git remote -v #and it should be showing : origin https://github.com/jamirawan/nasigoreng.git (fetch) origin https://github.com/jamirawan/nasigoreng.git (push)
- Push your commits to the upstream origin then your branch:
git push -u origin main
New repository on Github
When you created a repository on Github, it comes with instruction below
Quick setup — if you’ve done this kind of thing before Get started by creating a new file or uploading an existing file. We recommend every repository include a README, LICENSE, and .gitignore.
…or create a new repository on the command line
echo "# iirawan" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:iirawan/iirawan.git
git push -u origin main
…or push an existing repository from the command line
git remote add origin git@github.com:iirawan/iirawan.git
git branch -M main
git push -u origin main
…or import code from another repository
You can initialize this repository with code from a Subversion, Mercurial, or TFS project. Import code