Skip to content

Latest commit

 

History

History
135 lines (114 loc) · 2.65 KB

git-commands.md

File metadata and controls

135 lines (114 loc) · 2.65 KB

Git Commands

Start project from scratch

mkdir /path/to/your/project
cd /path/to/your/project
git init
git remote add origin [email protected]:briansaycocie/project_name.git

Add existing project

cd /path/to/my/repo
git init
git remote add origin [email protected]:briansaycocie/project_name.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push -u origin --tags # pushes up any tags

Clone in existing folder

cd /path/to/my/repo
git init
git remote add origin [email protected]:briansaycocie/project_name.git
git fetch origin
git checkout -b master --track origin/master

Ignore committed files

git update-index --assume-unchanged path/to/file.txt
git update-index --no-assume-unchanged path/to/file.txt

Undo local commit

git reset HEAD~1

Remove local untracked files from working tree

git clean -n (shows what will be deleted)
git clean -f (deletes files)
git clean -fd (deletes files and directories)
git clean -fX (deletes ignored files)
git clean -fx (deletes ignored and non-ignored files)

Merge feature_branch to master

commit changes in feature_branch
git co master
git merge --no-ff feature_branch
(if push failed) git reset --hard origin/master
git push

Revert merge

git reset --merge ORIG_HEAD
git reset --hard HEAD

Create new branch

git checkout -b new_branch

Checkout new branch

git fetch && git checkout new_branch

Clone specific branch

git clone [email protected]:briansaycocie/project_name.git -b branch_name

Tag and archive branch

git co feature_branch
git tag archive/feature_branch
git push origin archive/feature_branch
git co master
git branch -d feature_branch
git push origin --delete feature_branch

Remove local branch

git branch -D local_branch

Remove remote branch

git push origin :remote_branch

Configure upstream, git pull short command

git branch --set-upstream-to=origin/<branch>

Fix “your branch is ahead of x by x commits”##

git reset --hard origin/master

Replace local branch with remote branch entirely

git reset --hard origin/master

Bring old feature branch up-to-date with master

git co feature/branch
git rebase master

Change repo url

git remote -v
git remote set-url origin [email protected]:user_name/project_name.git (or git remote rm origin, then git remote add origin git@bitbucket...)
git remote -v

Remove file from repo

git rm --cached file.js

Sync forked repo with master repo

git pull upstream master