Child pages
  • Version Control with Git and Github

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The names of the files in your project directory that aren't being tracked should be placed in a file called .gitignore. Each subdirectory in a repository can have its own .gitignore file.

To stop a file from being tracked on Github without deleting the file locally, we can use

Code Block
git rm --cached [filename]

This will remove the file from Github without deleting it locally. If the filename exists in the .gitignore file, the file won't be tracked going forward.


If the remote copy of your repository is ahead of the local copy, you need to pull the remote copy. On the master branch, this is done with

...

To push the branch to Github:From here the advice I would offer depends on what your goals are. Are you interested in maintaining a few local git repositories to keep track of your analyses? Are you interested in creating a github account and have a few repositories on there? Or are you interested in jumping in and trying to help out on some of our projects?
The general set of abilities you'll need for all of them is:
To create a git repository - `git init` to turn in a directory into a git repository
To add files to your new repository - `git add <some-files>` - to tell git to manage those files for you
To tell git you've made some changes you want to keep - `git commit -a` - will add all of your changes
To send code to github is a bit more complicated (but once it's set up it's simple)
To learn more about github if you want to avoid the command line you can do most of the basic tasks from github directly. They maintain pretty good tutorials too.

Code Block
git push origin [branch name]

When work on a branch is finalized, it can be merged into the master copy of the repository. This is done by merging the local branch into the local master and then pushing the local copy of the master to the remote. To merge a branch back into the master, switch to the master branch and execute

Code Block
git merge [branch name]

The changes then need to be pushed to the remote.


The converse can be done if changes were made to the master that are not on a given branch. Then the master can be merged into the branch by switching to the branch locally and running

Code Block
git merge master


Merging branches may result in conflict if a file is changed in multiple ways in different branches. Changes must be consolidated before branches can be merged.

Once the purpose of a branch has been fulfilled, the branch can be deleted. To delete locally:

Code Block
git branch -d [branch name]

To delete a remote branch:

Code Block
git push origin --delete [branch name]


References

This content is based on the following references. More information and help can be found there.