This is the online reference I am using. However when I enter the remote repository and hit publish I get an error
You cannot publish local branch master to the remote repository origin
because a branch with the same name already exists there. You might
want to rename your local branch and try again.
I dont want to rename anything as yet. I want the first version of the code to go into the master branch and at the same time create an upstream tracking branch locally.
Then I tried using the command line only. After creating a fresh repository, I ran the following commands
$ cd (project-directory)
$ git init
$ (add some files)
$ git add .
$ git commit -m 'Initial commit'
$ git remote add origin <url>
$ git push --force
This worked but now I have all my obj,bin,packages directories along with it. I don't want all those directories to go. Editing the git ignore did not help either. What I am doing wrong? Its taken more twice the amount of time to get the code into the repository than it has taken to write the code!
I only want my sources in the repository and have a tracking local branch to begin with.
Related
I created my first GitHub repository using GitHub Desktop (Windows). It is a real mess with many revisions that are quite meaningless and some versions of files that I would rather were never uploaded. This was the result of a lot of experimenting to get the feel for how things would appear on GitHub. I want to get rid of all the history versions.
I am tempted to just copy my files on my drive to another folder then delete the repository folder from my drive. Also delete it from GitHub.
Then create a new repository with GitHub Desktop, perhaps with the same name or with a different name then rename it to the original. Could it be a simple as that or will GitHub still retain the files somewhere?
I haven't tried this because in my searching I keep finding all the complex steps to be performed to remove histories or remove files.
I sort of feel that what I am proposing is too simple.
Any opinions?
All of this got too confusing.
I just did what I said in the start of the thread.
It seems GitHub Desktop has some Username/Password problem and won't let me "Publish branch".
So I went to GitHub and created a new repository and uploaded all the files from my local folder.
It looks good to me.
There may be problems in the future. I guess I'll cross that bridge when (if) I come to it.
An alternative approach is to switch to command line and:
delete the .git folder in your repository
recreate it (git init .)
reset the origin remote: git remote add origin https://github.com//
Make a first commit with your current content:
git add .
git commit -m "first commit"
overwrite everything on the remote repo
git push --force -u origin master
The end result will be the same repo but with only one commit.
You can then switch back to GitHub Desktop.
From here.
First make sure you have Git for Windows installed, you are going to need to do git commands manually sooner or later.
Go to your local repository on your computer where your project is located. It's a good idea to show hidden files so you can see that you have the .git-folder and that the .gitignore-file is in place.
Go to the folder where the .git-folder is, right-click and click git bash here.
Now enter these commands:
Create Orphan Branch – Create a new orphan branch in git repository. The newly created branch will not show in ‘git branch’ command.
git checkout --orphan temp_branch
Add Files to Branch – Now add all files to newly created branch and commit them using following commands. Don't forget .gitignore!
git add .
git commit -m "the first commit"
Delete master Branch – Now you can delete the master branch from your git repository.
git branch -D master
Rename Current Branch – After deleting the master branch, let’s rename newly created branch name to master.
git branch -m master
Push Changes – You have completed the changes to your local git repository. Finally, push your changes to the remote (Github) repository forcefully.
git push -f origin master
Git overview
I uploaded my whole project on my repository of github yesterday.
I'd like to update the online version today, and when I use git push -u origin masterorder, the bash window says:
! [rejected] master -> master (fetch first)
So how do I "fetch"?
If I use git pull first, would my local files be overwritten by the online version?
So how do I "fetch"?
By using the command:
git fetch
Basically, your local repo is out of sync with the remote (Github) repository. If you have multiple remote repos, you can specify which one, and you can also specify which branch. Try
git help fetch
for a complete description of the command and the various parameters you can pass in.
If I use git pull first, would my local files be overwritten by the online version?
git pull is like doing a git fetch followed by git merge -- that is, it gets the updates from the remote and attempts to merge those into your local files. That may be fine, or not, depending on what you intend. Read the help for both commands so that you can make an informed decision.
Hello I recently started using github. I was able to make my first commit and upload my Java projects whole source folder to my only Repo. Now I have made changes to my files and would like to recommit the same files but after two hours of tutorials I am still stuck.
This is the process I have been doing.
Windows 8
Gitbash
cd ~\javaProjectSourceFolder(lets call it java)
git init
initializes
git add -A
git status
nothing to commit, working directory clean
I realize I am a newb and that I am not able to "add" my files. Can somebody help me out?
Please make sure you are on the right branch. If not then do the following from the terminal on the repository path. You should do your changes to a local branch, that may be the clone of the master. And next time follow these steps.
git branch :This will list all your branch. You must see master branch over there.
git checkout master : This will make you to switch on the master branch.
git checkout -b local_branch : This will create a branch with local_branch name & then you can add all your code here.
git add -A : this will automatically add the files that are even newly created or modified or deleted.
git commit -m "my commit message : This way you can do a commit to all changes.
git pull origin HEAD : This will update the current branch with any changes (in case of shared repository) You can avoid this as you are the only one working on your only repo.
git push origin HEAD : This will push your changes to the remote branch, but it will not merge this to the master unless you either push it to master or try merging from web on git hub.
For more information on each & every command, please refer the treasure here
Have an existing repo in git-hub with the projects files.
On a new machine, got into the target directory, e.g. myproject, and do this:
$ git init
$ git remote add origin https://github.com/myco/myproj.git
$ git pull (this downloads lots of files)
$ ls (no files)
$ git branch --set-upstream master origin/master
$ ls (no files)
$ git status ( shows all the files are marked for deletion! )
I have used this recipe before, no idea why doing a checkout of a repo causes it to delete all the repos files.
If I try and do the git branch before the git pull, it gives an error.
I cant use git clone, as ultimately, I need to have the files checked out into an eisting directory which already will have some project donfig files (not in git).
Any ideas?
If that is in fact the exact sequence of commands you followed, then here are some comments to help you understand where you are:
$ git init
Since it seems like you entered an empty directory (on a new machine, ...), this creates a new repository out of your current directory. This repository has no objects, no master branch yet, no commits, etc...
$ git remote add origin https://github.com/myco/myproj.git
This adds your origin repository and shouldn't be a problem.
$ git pull (this downloads lots of files)
This does two things - git fetch to collect all objects, branches, etc. that your origin repository currently has but your local repository doesn't (i.e. everything, since you're in a currently empty repository), followed by git merge. The merge phase should have failed here, with a message the the effect of "you didn't tell me what you want to merge, so I'm not going to do it".
$ ls (no files)
Right. You still haven't checked anything out, and since the git merge above failed, it never got to the point of updating your working directory.
$ git branch --set-upstream master origin/master
Now you are creating a master branch that has origin/master as its upstream, and as its starting point. However, this does not check out the branch, which leaves your working directory in the same state it was before, i.e. empty.
$ ls (no files)
You still have not checked anything out, so this is expected.
$ git status ( shows all the files are marked for deletion! )
git compares your empty working directory with what it thinks should be there, and determines that you must have removed everything.
What you really wanted to do there is this:
$ cd directory/where/you/want/your/repository
$ git clone https://github.com/myco/myproj.git
$ cd myproj
Then, copy your additional project config files into place.
If you really want to do it all the manual way, use git fetch instead of git pull, and after your git branch ... line, do a git checkout master (or do git checkout -b master origin/master in place of the git branch ... line, which implicitly does the branch setup before checking out the files).
I am beginner for gitHub. I have used svn before but I am not getting grip on github after going through many tutorials on the net. I have no idea about basic work flow. I created clone by using github. If I make any change in file suppose file_A then what is right step to push this file on server:
I am assuming :
git status->git commit->git pull -> git push
I have doubt that it push all project files on server But i was expecting to update only file_A. Please suggest me complete command/syntax with file path.
You are not pushing files but changes. So if you have cloned a repository with a lot of files and only changed one of them, you're only sending in the change to that one file. In your case that would be:
git clone git#github.com/some/repo .
git status # nothing has changed
vim file_A
vim file_B
git status # file_A and file_B have changed
git add file_A # you only want to have the changes in file_A in your commit
git commit -m "file_A something"
git status # file_B is still marked as changed
You can and should continue doing changes and commiting them until you're pleased with the result. Only then you should push the changes back to GitHub. This assures that everybody else cloning the repository in the meantime will not get your potientially broken work-in-progress.
git pull origin master
git push origin master
will send in all commits you made after you cloned the repository.
If I could make a suggestion - you might find it easier to not focus first on Github. Instead, if you have not already, go through an online book/tutorial for git (not Github) and learn the basics of git using the command line on your local machine and without involving a remote server or service like Github. In fact you do not even have to be connected to the Internet to learn much of git. This online book is excellent and starts at the beginning and teaches you how git works. Once you are confident in the basics you can start connecting to remote machines like Github.
Git Commands to update files in git:
To Add Upstream: (Initially You need to do it)
git remote add upstream
Save Local Changes to Temp
git stash save
Updating Local From Master
git pull --rebase upstream master
Apply Local changes Done earlier on latest Code taken from git master
git stash apply
To Update Fork:
git Status
git add "Resource Name to Add to Fork"
git Commit -m " Comments"
To Put these changes in Master:
git Push
Then Create Pull Request from Fork
Updating Fork From Master
git push origin master