Loading...
 
JoiWiki » Developer » Applications » Git » Git Concepts and Setup » Setting up a New Repo Setting up a New Repo

Setting up a New Repo


 Tracking a new folder is easy in git and once you've decided what you want it should take minutes to start developing with version control. 

 

Local Repo

 You don't need to track things on a server, git is great for version controlling anything. Obviously you'll miss out on proper disaster recovery in that if your machine dies, so to the git files but if you want to experiment with a large file/folder/project and easily come back to an earlier state this might be a good way to go and it couldn't be simpler:

  • Navigate to the folder that you want to track
  • Right-click and select Open Git Bash Here
  • Enter the following command
    • git init
  • Add a gitignore file
    • touch .gitignore
  • At this point you want to set up your gitignore file to ignore any filetypes
  • Make your first commit to master to capture the initial state of the folder/repo
    • Check the unstaged files
      • git status
    • Add files to staging
      • git add .
    • Commit to master
      • git commit -m "Initial commit to repo"

From this point you can branch off of master and track changes as you normally would. One of the advantages of this approach is that you can track folders that are already full/in use whereas you can only clone a project into an empty folder.

 

Setting up a Remote Repo

 We're currently using BitBucket as our remote repo storage so mosy over to their website and log in. They've got a page showing how to set up a repo on their services but you basically just hit the big + on the left hand side and select repository. Once you're there set the following details:

  • Owner: You, unless you're working with a team and want to give access
  • Project: select from one of the available or cancel out and make a new one
  • Access Level: Private
  • Include Readme: Up to you, if you want some files in your repo on startup this is a nice way to go, you can delete them later
  • Version Control: Git

Hit Create Repository and you're there, you'll be navigated to the new repo page and can hit the clone button to get the link to clone the repo onto your machine. Once you've cloned your repo to your machine in this way you can create branches and add files/folders/projects to the folder and push them to the remote via the origin keyword as you normally would.

 

Pushing a Local Repo to a new Remote one

 As mentioned above, you can't clone a repo into a folder that has any files in it but there are some folders that need to stay where they are because they're referenced by software or you simply don't want to have to shuffle the files around to get to where you need to be, in this instance it's better to create separate repos and push between them:

  • Set up the remote repo first as described above.
  • Set up a local repo in the folder that you'd like tracked, as above.
  • Go to the repo page on bitbucket and click on the clone button on the top right to get the link to the repo (the bit after git clone)
  • Head back to your bash prompt and enter the following:
    • git remote add origin [RepoLink]
  • Then verify your settings with:
    • git remote -v
  • Once this is done all you need to do is to push your changes up to the remote
    • # Push up to a branch to create a pull request, replace 'newbranch' with desired branch name
      git push origin newbranch
      
      # Push directly to master
      git push origin master


Depending on whether you pushed to master or not will mean that you might need to make a pull request to merge into master or you might want to leave the content as a branch and merge developments into that but at this point your folder contents are tracked by git and backed up to a remote.
 

 

 

 

 

Created by JBaker. Last Modification: Thursday September 26, 2019 14:41:09 BST by JBaker.

Developer