Adding an existing project to GitHub using the command line
Putting your existing work on GitHub can let you share and collaborate in lots of great ways.
If you are migrating your project from CodePlex, read the migration guide for more information.Hub Desktop Help.
gitignore
files. You can add these files after your project has been pushed to GitHub.- Open Git Bash.
- Change the current working directory to your local project.
- Initialize the local directory as a Git repository.
$ git init
- Add the files in your new local repository. This stages them for the first commit.
$ git add . # Adds the files in the local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.
- Commit the files that you've staged in your local repository.
$ git commit -m "First commit" # Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.
- At the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL.
- In the Command prompt, add the URL for the remote repository where your local repository will be pushed.
$ git remote add origin remote repository URL # Sets the new remote $ git remote -v # Verifies the new remote URL
- Push the changes in your local repository to GitHub.
$ git push origin master # Pushes the changes in your local repository up to the remote repository you specified as th
To checkout a specific feature branch
git clone -b <branch> <remote_repo>
When you do a pull request on a branch, you can continue to work on another branch and make another pull request on this other branch.
Before creating a new branch, pull the changes from upstream. Your master needs to be up to date.
$ git pull origin {name of the remote branch}
Create the branch on your local machine and switch in this branch :
$ git checkout -b [name_of_your_new_branch]
Push the branch on github :
$ git push origin [name_of_your_new_branch]
When you want to commit something in your branch, be sure to be in your branch. Add -u parameter to set-upstream.
You can see all the branches created by using :
$ git branch -a
Which will show :
* approval_messages master master_clean
Add a new remote for your branch :
$ git remote add [name_of_your_remote] [name_of_your_new_branch]
Push changes from your commit into your branch :
$ git push [name_of_your_new_remote] [url]
Update your branch when the original branch from official repository has been updated :
$ git fetch [name_of_your_remote]
Then you need to apply to merge changes if your branch is derivated from develop you need to do :
$ git merge [name_of_your_remote]/develop
Delete a branch on your local filesystem :
$ git branch -d [name_of_your_new_branch]
To force the deletion of local branch on your filesystem :
$ git branch -D [name_of_your_new_branch]
Delete the branch on github :
$ git push origin :[name_of_your_new_branch]
If you want to change default branch, it's so easy with GitHub, in your fork go into Admin and in the drop-down list default branch choose what you want.
If you want create a new branch:
$ git branch <name_of_your_new_branch>