👩‍🏫 Courses

How to's

How to initialize and upload a local repository to GitHub

  • Create a new empty repository on your GitHub account.
  • Initialize your local folder (new or existing) as Git repository using git init
  • add files to staging area using below commands
git add .
git commit -m "your comments go here"

push this repository to the new repository on GitHub

git remote add origin https://github.com/<your-github-account>/<new-repo-name>.git
git push -u origin master

How to create a new branch?

git checkout -b feature_branch_name

Note: First make sure your repository is up to date with the latest commit on master using git pull origin master. git pull does a git fetch followed by a git merge to update the local repo with the remote repo.

How to create a new brach from an existing branch?

git checkout -b feature_branch_name base-branch-name

How to commit changes?

After editing the files, add and commit your changes:

git add . to add all changes

git commit -m "Comment text"

Or git add <file> to add only a particular file.

or git commit -am "Your message" to add and comment as single action.

How to push code to repo?

git push -u origin feature_branch_name

How to list all remote branches in Git?

git branch -r or

git ls-remote or

git ls-remote --heads command will list all branches available on the remote repository

You can also do git ls-remote [url] if you don't want to clone the repo first.

Note: typing q should get you out of the listing mode generated by the git.

How to create a pull request?

  1. After pushing your local changes to your remote repository, point your browser to your repository on Github
  2. Click the Pull Requests tab.
  3. Click New pull request.
  4. In the base: dropdown, select master .
  5. In the compare: dropdown, select the branch you recently pushed to the repository.

Learn more: https://yangsu.github.io/pull-request-tutorial/

How to check remote URL

git remote -v

How to remove origin from git repository

git remote rm origin