Skip to content

git it got it good

Chris edited this page Jan 18, 2018 · 12 revisions

to turn any directory into a git repo run the following command within the directory

git init

to remove git from a directory / project, just delete the .git directory in the root of the project. to add a remote repo for a git project

git remote add origin <URL>

to display the remote URL’s of a git project

git remote -v

to copy a remote git repo to a local box run the below command

git clone <URL>

to stage all the changes displayed from git status run the below command

git add .

or

git add -A

to commit all the changes for a push to the remote repo run the below command

git commit -m β€œCommit local changes”

to push all the committed changes to a remote repo run the below commandto push all the committed changes to a remote repo run the below command

git push

Sync local / remote repos with git pull

git pull is a shortcut of two other git commands

git fetch
git merge
git fetch; git merge

Isolate feature development with git branch

to create a new branch that isolates a feature / fix run the below command

git branch new-feature

to display all the branches of a git repo run the below command

git branch

to switch to the new-feature branch run the below command

git checkout new-feature

to create a new branch and switch to it run the below command

git checkout -b new-feature2

to switch to the last checked out branch run the below command

git checkout -

will switch back to the master branch

Sync branches with git merge

to combine the new-feature branch with master run the below commands

git checkout master
git merge new-feature

to delete a branch after everything is complete with it, run the below command

git branch -d new-feature

Resolve merge conflict with git status

A merge conflict arises when the local and remote code both change, and it can’t be resolved with a standard git pull or git push There are three possible scenarios to resolve a merge conflict use git status to see the file in question that is causing the merge conflict

Save uncommitted changes with git stash

git stash allows you to save your local changes after staging them

git add .
git stash

Clone this wiki locally