git pull is used to fetch/download new content from a remote repository and immediately update the local repository with that content. git pull is a combination of git fetch and git merge. In the first step of operation git pull will execute a git fetch scoped to the local branch that HEAD is pointed at. Once the content is downloaded, git pull will enter a merge workflow. A new merge commit will be-created and HEAD updated to point at the new commit.
// update local branch with new commits from the remote repo. git pull // update local branch with new commits from the remote. New commits from remote will be applied under new changes on local. // In other words, your local changes will be on top of the new commits from remote. git pull --rebase

git fetch vs git pull
git fetch is a safe option whereas, git pull is a unsafe option. git fetch will download the remote content but not alter the state of the local repository. git pull will download remote content and immediately appy the remote changes to local state of the local repository.
git push is used to upload local repository commits/changes to a remote repository. This is how you transfer commits from your local repository to a remote repo. It’s the counterpart to git pull or git fetch. Pushing has the potential to overwrite changes so you have to be careful when pushing.
// push local commits/changes to remote git push // force the push even if it results in a non-fast-forward merge. Do not use the --force flag unless you’re absolutely sure you know what you’re doing. git push --force
git commit is used to take a snapshot of the project’s currently staged changes. Commits are the core building block units of a Git project timeline. Commits are created with the git commit command to capture the state of a project at that point in time. Git Snapshots are always committed to the local repository.
You can have multiple commits on local. When you are ready, you can then push your local commits to remote with git push
// add certain files(index.html) to commit git add index.html // or add all updated files to commit git add . // commit a snapshot of all changes in local repo git commit -a //By default, git commit will open up the locally configured text editor to add a commit message. //Passing the -m option will forgo the text editor prompt in-favor of an inline message. git commit -m "setup" // create a commit of all the staged changes and takes an inline commit message. // shortcut for (git add .) + (git commit -m "message") git commit -am "setup"
The git clone command is used to clone or copy a remote repository onto a destination such as your laptop or a remote server.
Git supports ssh and https network protocols.
Git clone ssh
git clone ssh://folauk@gmail.com/path/to/my-project.git // example git clone ssh://git@github.com:folaulau/spring-data.git
Git clone https
git clone http[s]://host.xz[:port]/path/to/repo.git // example git clone https://github.com/folaulau/spring-data.gitApril 5, 2019
The git init command is used to create a git repository. The git init creates a .git subdirectory which contains the git metadata for the repository. Keep in mind that the current directory in which you run the git init command will be the repository.
// make the current direct a repository git init
// create a new repository in a new directory git init directory-name // example git init test-repo
If your run git init again in a repository it will not overide the existing configurations.
How to create a new local repository and push it to remote
*** All though this works, it is better to create a remote repository and then clone it to your computer or server.
April 5, 2019