Skip to content

Instantly share code, notes, and snippets.

@chand
Last active October 2, 2017 01:16
Show Gist options
  • Save chand/1e37092b832d62f1296c5116b7f2fa2c to your computer and use it in GitHub Desktop.
Save chand/1e37092b832d62f1296c5116b7f2fa2c to your computer and use it in GitHub Desktop.
Git Workflow.md

Git Workflow

Adding Files fom Feature Branch

  1. In command line:
git add .
git commit -m "[add message here]"
git push origin [branch-name]
  1. Go to github repo in browser and open pull request
  2. Merge changes
  3. Back in command line:
git co master
git pull origin master

Rebasing

If someone else has pushed up and you want to pull down their work.

If you are in another branch working on something, In command line:

git add .
git commit -m "commit message"
git checkout master

If you are in master branch with no changes to make, in command line:

git pull origin
git checkout branch_name

(if you create a NEW branch at this time, you do NOT need to rebase, only rebase if you switch to an existing feature branch. If you create a new branch, it creates the same versions from master)

git rebase master

Merge conflict from rebasing

Command line will show you which file(s) has the merge conflicts. Go into those files and delete errors/duplicates etc. When you are sure it is correct:

git add .
git rebase --continue 

if you have more merge conflicts, it will tell you which file(s), if you want to ignore those files and NOT fix them:

git rebase --skip
git push origin branch_name

If i am ready to push my changes

In feature branch:

git add .
git commit -m "commit message"
git checkout master
git pull origin master
git checkout branch_name

(if you create a NEW branch at this time, you do NOT need to rebase, only rebase if you switch to an existing feature branch. If you create a new branch, it creates the same versions from master)

git rebase master
git push origin feature-branch-name

Go to github repo in the browser and pull request/merge etc.

Clone repository from someone else and make it a master in your own repository

  1. Create a new repo in your github account (public, no license)
  2. Git clone repo to your desktop that you want to push up to your repo, navigate to the directory you want to clone it to via command line
git clone https://github.com/user_name/project_name.git
mv project_name new_project_name (if you want to change the name of the repo/project)
cd new_project_name
git remote -v (this should be the original repo location)
git remote remove origin 
git remote add origin https://github.com/URL_OF_NEW_REPO (will be provided when you created the new repo in the first step)
git remote -v (double check that the origin was switched from the old repo location to your new one)
git push origin master

Clone your own branch of a repository

  1. Navigate to directory you want to clone/pull down in console 2.Git clone main challenge URL, ie:
git clone https://github.com/user_name/project_name.git
cd project_name
git pull origin branch_name

Remove Git from a directory

In the directory that git has initialized:

rm -rf .git/

Add existing folder to GitHub

  1. Create new repository in github
  2. in terminal, go into the folder and type:
git init
git add .
git commit -m "First commit"
git remote add origin https://github.com/chand/[nameofrepo].git
git remote -v
git push -u origin master
  1. refresh the github repo page to ensure that the files were pushed correctly.

Roll back a commit during merge conflict

git reset --hard HEAD

Resolve Merge Conflict during pull request when pushing from feature branch

Merge master into my feature branch

git pull origin master
git co master
git pull origin master
git co feature-branch
git merge master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment