- fork the repo you want to work on by clicking "fork"
- clone the repo to your desktop. In your terminal, type the following:
git clone --recursive https://github.com/YOUR_USERNAME/REPOSITORY_NAME.git
- set up a remote named origin. In your terminal, type the following:
git remote add origin https://github.com/YOUR_USERNAME/REPOSITORY_NAME.git
- set up a remote named remote. In your terminal, type the following:
git remote add origin https://github.com/OWNER_USERNAME/REPOSITORY_NAME.git
- run
git remote -v
to check the status of your remote setup. You should see the following:
origin https://github.com/YOUR_USERNAME/REPOSITORY_NAME.git (fetch)
origin https://github.com/YOUR_USERNAME/REPOSITORY_NAME.git (push)
upstream https://github.com/OWNER_USERNAME/REPOSITORY_NAME.git (fetch)
upstream https://github.com/OWNER_USERNAME/REPOSITORY_NAME.git (push)
- Make sure to be on your master branch.
-
To check which branch your currently on:
git branch
-
To go to your master branch:
git checkout master
- Update your local master branch to be in sync with the upstream master branch repository:
git pull upstream master
NOTE: If there are confilicts, resolve them.
- Review the changes and ensure they are satisfactory (run and test the project)
- Push this to your remote origin repository:
git push origin master
- Go to a branch to develop a new feature:
-
To switch to an existing branch:
git checkout existing_branch_name
-
To create a new branch and switch to that branch:
git branch -b new_branch_name
- Sync your new branch with your master branch:
git merge master
- Develop a new feature
- Go back to your master branch (once you are sure that your current branch is good and ready to be put into master)
- Merge the branch you worked on with your master branch:
git merge your_branch_name
- Push this to your remote origin repository:
git push origin master
- Why use branches?
by diverging from the main line of development, you can continue to do work without messing with that main line.
Useful Commands for Branching
-
To create a new branch:
git branch new_branch_name
-
To create a new branch and switch to that branch:
git branch -b new_branch_name
-
To list all your remotes:
git remote -v
-
to change remote's URL:
git remote set-url REMOTE_NAME NEW_URL
- You need to commit your changes or stash them before you can switch branches; otherwise, your local changes will be overwritten.
git pull upstream master
is same asgit fetch upstream
+git merge upstream/master
- To change a remote's URL:
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
orgit remote set-url origin [email protected]:USERNAME/REPOSITORY.git
- To find out the exact commit that made an unwanted change:
git bisect A_KNOWN_GOOD_COMMIT_ID
...To be added