Steps to setup git repo
Setup git repo environment:
-
Setup user details
git config --global user.name "Your name here" git config --global user.email "your_email@example.com"
-
Generate SSH key(skip to next step to reuse existing ssh key)
a) For Mac . (Read more about SSH keys)
ssh-keygen -t rsa -C "your_email@example.com" b) Copy SSH key pbcopy < ~/.ssh/id_rsa.pub For Windows,
a) Either use putty.exe or open git bash and type
ssh-keygen -t rsa
then look under
your_home_directory/.ssh/id_rsa.pub
path and openid_rsa.pub
file then copy(excluding spaces) the content(SSH key) -
Add SSH key to account
a) Go to https://github.com/settings/profile
b) Open SSH key section or use https://github.com/settings/ssh
c) Paste your key and save it
Setup local repo for new project:
-
Setup new repository
git init -
Create
.gitignore
file(for new repo) and add content from .gitignore android file, Optionally can create and addREADME.md
for project documentation -
Add file(s) to staging using (use
git status
to view the staged/unstaged changes)git add path/filename or add all files using git add .
-
Commit the previously staged changes
git commit -m "init repo message"
-
Push changes to the remote repo
a) Create a new project under github/gitlab/bitbucket account, etc and copy the SSH-link
git remote add origin https://github.com/UserName/RepoName.git
b) Pull auto-generated license or README file
Caution: use
--allow-unrelated-histories
only once for new repo to pull the license, README files.git pull origin master --allow-unrelated-histories
c) Push code
git push origin master
Setup local repo using clone:
-
Clone existing project from github using
git clone SSH-link.git ![ssh_link](https://user-images.githubusercontent.com/11755381/75903716-fd262780-5e67-11ea-873d-bdc4377da81a.png)
-
Add file(s) to staging using
git add path/filename or add all files using git add .
-
Commit the previously staged changes
git commit -m "init repo message"
-
Push changes to the remote repo
a) Verify the exiting remote repo link:
git remote -v
In case of no remote URL, add one using
git remote add origin https://github.com/UserName/RepoName.git
b) Push code to
master
branchgit push origin master
Note: To reset an existing remote URL use
git remote set-url origin repo-link
.
Pull Sub-module
For large repositories with submodules, it’s recommended to update them recursively as:
git submodule update --init --recursive