8

I know there are hundreds of tutorials out there on this, but I couldn't figure where to start. I am using a MAC and am on a remote system which runs Ubuntu 14.04. What I want to do is upload folders to my organization's github repository. There already exists a repo, and I want to create a branch and upload my files and folders in that branch.

I tried doing

git branch branch_name
git checkout branch_name

However the branch does not show up on the webpage. I also tried creating a branch from the webpage, but I dont know how to upload files to it. I am also not sure how to actually navigate to the repository to which I want to upload.

Please give me instructions as to how I could go about doing this.

Thank you!

4

4 Answers 4

26
  1. Find your repository. (Pick the folder you think it's in, and run ls -a. If you see .git, you're probably in the right place.
    • If you do not have the repository initilized yet, do one of the following:
      • If you have all the files copied from the repository, all you need to do is git init.
      • If you have nothing, run git clone <https://something/foo/bar.git> <folder you want the repository to be in>. If you specify nothing for the folder, it will create it in the current folder.
  2. Create a branch: You can use a single command instead of the two commands you have in your question: git checkout -b <your branch name>
  3. Make some changes in the files.
  4. Track your changes: git add <changed file> [<another changed file> [...]] Note that a changed file can be a folder.
    • If you deleted a file, use git rm <file> so Git knows you deleted it.
  5. Commit your changes: git commit -m "what you did"
  6. If you need to push your changes back to the main branch, use git checkout master and git merge <your branch name>. This will move all commits on your new branch to the original branch.
  7. Push your changes to the online repository: git push
    • For your first time pushing any branch, use this instead: git push --set-upstream <https://something/foo/bar.git> <your branch name>
    • From now on, you can incorporate changes from the online branch to your local by using git pull.
    • If changes are made on master that should be in your branch, checkout your branch and use git rebase master.
4
  • Thanks, I needed the details ;) . So before I do this, I initialize my repository by doing git init right?
    – rowana
    Nov 17, 2016 at 14:18
  • 1
    @rowana No, you should already have the repository. git init is for creating a new repository. You just want to create a new branch in an existing repository.
    – Gavin
    Nov 17, 2016 at 14:23
  • I did not actually git clone when i downloaded, instead I just downloaded the entire repository as a folder.
    – rowana
    Nov 17, 2016 at 22:31
  • Oh well then git init.
    – AAM111
    Nov 18, 2016 at 0:38
3

You need to push your branch to your remote repository. Notice that the -u option sets the upstream for your local branch, so that every following push refers to the given remote branch.

git push -u origin branch_name

If you don't have any configured remote repositories yet, you can do so by copying the URL of your repository and add it as a remote repository.

git remote add origin git@github.com:/YOU/REPO.git
3
  • Doing git remote add newBranch git@github.com:/YOU/REPO.git added all the files to master branch and moved the files from master to newBranch. So what is the correct syntax of the command? Jun 16, 2019 at 7:08
  • It's git remote add newRemoteNameAlias git@github.com:/YOU/REPO.git. Afterwards, you are able push branches.
    – user5520186
    Jun 17, 2019 at 8:22
  • This helped to solve my issue
    – Ayan
    Jun 1, 2022 at 14:10
2
  1. Create a branch with git checkout -b <branch>
  2. Do stuff & commit
  3. git push --set-upstream <remote> <my_branch> e.g. origin <branch>

All of that if you have a remote set. If not, set a remote first.

2
  • How do I know if I am creating a branch in the right repository? (Because I just have a folder which I want to push, but no clue as to if I did it right..!)
    – rowana
    Nov 16, 2016 at 22:33
  • folder with .git folder == a repository. Nov 16, 2016 at 22:34
1
  1. creating a branch from the webpage
  2. git branch branch_name git checkout branch_name
  3. git push origin branch_name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.