i have a git lab repository , I was asked to create a new branch and push code that i have. I have verified lot of articles here and examples but not sure whehter i need all those different steps.
I have just gitbash installed on my pc and i have remote repository url and, have a folder where i have my code which needs to be added to that new branch
Can some one help me setup steps. My understanding i should perform below on my local pc is this correct?
git config --global user.name "your_username"
git config --global user.email "your_email_address@example.com"
cd into directory where you have local code
git clone https://gitlab.com/gitlab-tests/sample-project.git
git init
git remote add origin <git@gitlab.com:username/projectpath.git
git checkout -b <name-of-branch>
git checkout <name-of-branch>
git add .
git commit -m "COMMENT TO DESCRIBE THE INTENTION OF THE COMMIT"
git push <remote> <name-of-branch>
What you need to do is this:
# This gets a copy of the remote repository to your PC (login will probably be required)
# Replace the URL with the actual URL of the repo
git clone https://gitlab.com/gitlab-tests/sample-project.git
# get into the repository (replace with the repository's name)
cd sample-project
# get your code where it should go
cp <where your local code is> <where it should be in the repo>
# Get to the branch (use the command that applies to your case!)
# Create a new branch if it does note exist on the remote
git checkout -b <branch-name>
# Check out the branch, if it already exists
git checkout <branch-name>
# Add the new code
git add .
git commit -m "<add a meaningful comment here>"
# Push the code to the remote repository (use the command that applies to your case!)
# like this if the branch does not exist on the remote
git push --set-upstream origin <branch-name>
# like this if the branch already exists on the remote
git push origin <branch-name>
Further notice:
git config
commands before, if you did not do that yet, but it is not required.git init
will create a new repository which is not what you want to do. In case of gitlab, it will be done for you by gitlab.git remote add
yourself, if you clone from the correct URL.git push --set-upstream
if your branch does not exist on the remote repository as you can see in my code.