Skip to content

Instantly share code, notes, and snippets.

@daugaard47
Last active December 6, 2020 14:27
Show Gist options
  • Save daugaard47/6ad203e3cddef4736489e4fa477a6a26 to your computer and use it in GitHub Desktop.
Save daugaard47/6ad203e3cddef4736489e4fa477a6a26 to your computer and use it in GitHub Desktop.
Git Commands

Make Develop your default branch. If you only have a master branch, Create new develop banch. (See create a new branch below) This is where you will work 85% of the time. Only use Master branch for production ready code.

If you add a new feature, go to develop branch and then create a new branch with feature name. (See create a new branch below)

  • Once you're done with the new feature, Merge to develop.
  • Push to staging server and test (optional).
  • If all good on staging serve, switch to master beanch and merge develop branch into master.
  • Then switch back to develop branch and delete the new feature branch. (Sometimes you will have merge confilct due to CSS etc.. I use https://www.sublimemerge.com/ free version to fix these issues)

Git COMMANDS:

SWITCH BRANCHES

git checkout BranchName

SEE ALL BRANCHES

git branch

CREATE A NEW BRANCH:

1. Go back to develop branch 
2. git checkout -b NewBranch 
3. git commit -m "Init NewBranch" 
4. git push origin NewBranch 
5. git push --set-upstream origin NewBranch 
6. git push

DELETE BRANCH

1. git branch (See all branches) 
2. git push origin :branchname (Deletes branchname remote from github) 
3. git branch -D branchname (Deletes branchname from local)

RENAME A BRANCH

1. git branch -m current-branch new-branch 
2. git push origin :current-branch new-branch

PUSH STAGING TO LIVE SERVER

1. Switch from master to new branch 
2. Make sure your on new branch IE newbranch 
3. git push staging newbranch (Adds branch to /var/repo/dev.git/refs/heads) 
4. git push staging +master:refs/heads/newsponsor (swithches branch in /var/repo/dev.git HEAD from master to newbranch) 
5. git push staging (adds new changes to dev.example.com website)

GET A REMOTE BRANCH

1. git fetch origin <branch_name>

MERGING REMOTE BRANCH THAT IS NOT MINE

1. Fetch the remote branch from the origin first. 
2. git fetch origin remote_branch_name 
3. Merge the remote branch to the local branch 
4. git merge origin/remote_branch_name

GIT NAH

Use to clear all your changes to a branch prior to committing.

git reset --hard && git clean -df
//Create a alias
alias nah="git reset --hard && git clean -df"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment