6

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!

rowana
  • 638
  • 1
  • 7
  • 19
  • 1
    https://guides.github.com/activities/hello-world/ – Jim Nov 16 '16 at 22:28
  • Were your two commands followed by adding, committing, and pushing to the remote repo? – Gavin Nov 16 '16 at 22:29
  • @Gavin, No. I was following this tutorial: https://www.atlassian.com/git/tutorials/using-branches/git-merge. But stopped after the above mentioned two steps because I was worried that I might commit it to the master :( – rowana Nov 16 '16 at 22:32
  • Possible duplicate of [How do you create a remote Git branch?](http://stackoverflow.com/questions/1519006/how-do-you-create-a-remote-git-branch) – Peter Badida Nov 16 '16 at 22:35

4 Answers4

21
  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.
OldBunny2800
  • 966
  • 1
  • 17
  • 33
  • Thanks, I needed the details ;) . So before I do this, I initialize my repository by doing git init right? – rowana Nov 17 '16 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 '16 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 '16 at 22:31
  • Oh well then git init. – OldBunny2800 Nov 18 '16 at 00:38
1
  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.

Peter Badida
  • 7,432
  • 8
  • 33
  • 74
1

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
  • 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? – Pran Kumar Sarkar Jun 16 '19 at 07:08
  • It's `git remote add newRemoteNameAlias git@github.com:/YOU/REPO.git`. Afterwards, you are able push branches. –  Jun 17 '19 at 08:22
1
  1. creating a branch from the webpage
  2. git branch branch_name git checkout branch_name
  3. git push origin branch_name
ijal
  • 11
  • 1