Tuesday, June 2, 2020

Create new branch in GitHub

Note: OS Windows
Way 1:
Create new branch from the current branch and automatically switch to it.
$ git checkout -b <branch_name>

Way 2:
1. Create a new branch on the repository
$ git branch <branch_name>
2. Switch to the new branch from current branch.
$ git checkout <branch_name>

Way 3:
1. Create new branch and can specify a different branch which want to create the new branch.
$ git checkout -b <branch_name> <branch-name_which_creates_the_new_branch>

List all the branches in the repository
$ git branch

Saturday, May 9, 2020

Create new repository and add existing project to GitHub in command line

Note: OS Windows
1. Create new repository on GitHub. Do not add README and gitignore files, can add it after push the project to GitHub.

2. Open Git Bash.
3. Change the current working directory to your local project.

4. Initialize the local folder as a git repository.
$ git init
5. Add file to the local repository(Stages) to first commit.(To unstage a file, use 'git reset HEAD YOUR-FILE')
$ git add .
6. Commit files staged in the local repository.
$ git commit -m "First commit"
7. Copy the remote repository URL on GitHub.
8. Add/set the URL for remote repository
$ git remote add origin <copied remote repository URL>
(Optional : To verify remote URL - $ git remote -v)
9. Push changes.
$ git push origin master

Reference:
[1] https://help.github.com/en/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line