Initialize git, add remote origin and to set default upstream
git init
The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository. Most other Git commands are not available outside of an initialized repository, so this is usually the first command you’ll run in a new project.
git remote add origin {REMOTE_URL}
To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at.
The git remote add command takes two arguments:
- A unique remote name, for example, “my_awesome_new_remote_repo”
- A remote URL, which you can find on the Source sub-tab of your Git repo
For example:
#set a new remote
Two ways,1.git remote add my_awesome_new_remote_repo git@github.com:NilukaSripalim/flutter-mobile-app.git
# or
2.git remote add origin https://github.com/NilukaSripalim/flutter-mobile-app.git#Verify new remotegit remote -v> my_awesome_new_remote_repo git@github.com:NilukaSripalim/flutter-mobile-app.git (fetch)
my_awesome_new_remote_repo git@github.com:NilukaSripalim/flutter-mobile-app.git (push)
origin https://github.com/NilukaSripalim/flutter-mobile-app.git (fetch)
origin https://github.com/NilukaSripalim/flutter-mobile-app.git (push)
3.
git pull origin master
To push your changes into your remote repo, execute the git push <remote> <branch> command:
4.
git branch -u origin/branchName
# or
git branch --set-upstream-to=origin/master master
You update/set an upstream with the branch command. Branch branchName set up to track remote branch branchName from origin.
You can also set it with a push
git push -u origin master
git push --set-upstream origin master
5.
git pull
It fetches and merges changes from the remote server to your working directory. The git pull command is used to pull a repository.