-2

How to add project folder from my local machine to a git repository on Azure using GIT?

In the local directory for the root of the project

git init

git remote add origin <URL for Azure Git repo>

git add .

git commit -m 'initial commit'

git push -u origin master

I know these commands after doing a basic research on stack-overflow but my question is, if we have a branch named "dev" and I create a folder named "sandbox" in that branch, so if I want to add my project in that particular folder can I do just by copying the https link by going to that folder and what should be typed in

git push -u origin master

instead of master? Do I have to write "dev" as this is the branch I will be pushing my code in?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
psygo
  • 95
  • 2
  • 10

1 Answers1

2

To push to origin dev you can do

git push -u origin dev

A quick git tutorial

I'll explain how to create a git repo, create a new branch, setting upstream and pushing the branch to remote.

Init a git repo and make some dummy commits in master

# init a git repo
git init 

# Add a remote for the git repo
git remote add origin <URL for Azure Git repo>

# create a dummy file
touch file1

# stage all changes made to git repo so they can be commited
git add .

# make a commit for the staged changes
git commit -m 'initial commit'

# push commit to remote 
git push

# The same as previous step, buy done explicitly by specifying the remote address and branch name 
git push -u origin master

Adding a demo commit in a new branch

# create a new file
touch file2

# stage changes
git add .

# decided to push these changes to dev instead of the master branch
# create a new branch and checkout to dev
git checkout -b "dev"

# make commit to the dev branch
git commit -m 'dev commit'

# push the changes
git push

# or

# Only push the changes of dev to remote address origin
git push -u origin dev

In the end your git log would look like this (with pretty print and formatting)

* 2e48c23 - (HEAD -> dev, origin/dev)
|           dev commit - clmno
* fad2e5b - (master, origin/master)
            initial commit - clmno
clamentjohn
  • 3,417
  • 2
  • 18
  • 42
  • Sir, a little confusion I have. The branch dev is already present in the azure devops and they want me to commit and push in that branch only. So instead of creating a branch using "git checkout -b "dev" " I was writing "git checkout dev" it is giving me error, error: pathspec 'dev' did not match any file(s) known to git. What should I do now? just write git push -u origin dev, will it be automatically push my folder to that sandbox folder in dev branch? – psygo Dec 19 '20 at 08:18
  • 1
    @psygo you first need to make a commit to dev branch at your local machine. If you don't have the branch locally then first you need to pull it (git pull --ff-only). Then checkout to dev (git checkout dev), make changes and commit changes to dev. And finally push to dev (git push origin dev) – clamentjohn Dec 19 '20 at 18:43